【发布时间】:2017-06-04 06:35:30
【问题描述】:
有什么办法可以发送来自父母的任何道具,但有一个道具改变了?
我有一些页面,我正在渲染InputList 组件。在这个组件中,我再次渲染InputList。所以我要发送 {...this.props} 并更改一个道具 - modal。但是当我发送<InputList modal={true} {this.props}/>。 modal 值取自 ...this.props。所以值是false 而不是true,有什么提示吗?
当然,有可能单独发送所有道具,但我有很多道具,所以我想使用 this.props.. 或者我可以使用 const { modal, ...others} = this.props 之类的东西,但还有更多道具,我我正在使用所以我有const { modal,...,...,...,...,...} = this.props
class Page extends Component{
render(){
return(
<InputList modal={false} list={...} valueA={..} valueB={..}
firstTitle={..} secondTitle={..} />
)
}
}
class InputList extends Component{
render(){
const {modal,list,valueA,valueB,firstTitle,secondTitle} = this.props;
....
return(
....
<InputList modal={true} {...this.props} />
)
}
}
【问题讨论】:
标签: reactjs components parent-child render