我试图通过 style
属性将样式数据从父组件传递到子组件,但是我收到以下错误:
this is reserved word
这是与我的问题有关的相关代码:
child :
render {
return (<table>
<tr style={{backgroundColor: {this.props.color}}}> ...some text here...</tr>
</table>)
}
父级:
constructor(props){
super(props)
this.state = {
color: "red"
}
}
render() {
return <Child color={this.state.color} />
}
我错过了什么?
最佳答案
在您的子组件的 render()
方法中看起来像是一个小的语法错误。
删除 this.props.color
周围的 {
和 }
将解决问题:
<tr style={{backgroundColor: this.props.color}}> ...some text here...</tr>
关于javascript - ReactJS:这是保留字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54993076/