我已经使用“ react-switch”创建了用于切换的子组件,并尝试在父级中渲染该子组件。但是,我遇到了类似Invariant Violation的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件。请检查Temp
的渲染方法。
import * as React from 'react';
import * as Bs from 'react-bootstrap';
import Switch from "react-switch";
interface ITempProps {
}
interface ITempStates {
checked: boolean
}
export class Temp extends React.Component<ITempProps, ITempStates>{
constructor() {
super();
this.state = { checked: false };
this.handleChange = this.handleChange.bind(this);
}
handleChange(checked: boolean) {
this.setState({ checked });
}
public render() {
return <div className="new-main-content">
<h3>Test Switch</h3>
<div className="marL20">
<Bs.Row>
<Bs.Col className="text-left" sm={4} componentClass={Bs.ControlLabel}>
Toggle-Switch
</Bs.Col>
<Bs.Col>
<Switch
onChange={this.handleChange}
checked={this.state.checked}
className="react-switch"
id="normal-switch"
/>
</Bs.Col>
</Bs.Row>
</div>
</div>
}
}