【发布时间】:2018-12-14 13:45:57
【问题描述】:
错误':' expected 出现在渲染方法中并指向&&。 this.state.obj 的类型为 MyType。
type MyType = {
name: string,
};
constructor(props) {
super(props);
this.state = {
obj: null
};
}
componentDidMount() {
this.setState({obj: {name: 'Vasya'}});
}
render() {
return {this.state.obj && <MyComponent />};
}
【问题讨论】:
-
你不在 JSX 里面,
{没有开始插值;return {正在启动一个对象。