0
这里有应用程序根组件通过克隆将一个handleHeaderTitle函数传递给其所有子项。 儿童内部组件中,函数在componentWillMount() 中调用,结果根组件根据路由更新标题文本。子组件更改父组件状态
根:
{
this.props.children &&
React.cloneElement(this.props.children, {
handleHeaderTitle: this.handleHeaderTitle
})
}
handleHeaderTitle(title) {
this.setState({ headerTitle: title });
}
儿童:
componentWillMount() {
this.props.handleHeaderTitle("Profile");
}
Profile.propTypes = { handleHeaderTitle: React.PropTypes.func };
,提供了增加Redux的,因为国家是不是真的局部这里正在从其父一个子组件设置这个权利用例?
我想我需要创建像SET_PROFILE_HEADER和内部减速器这样的动作。但仍然搞清楚如何通知容器根组件,该子组件已更改标题标题
感谢Chardy,我使用了侧边栏组件(https://github.com/balloob/react-sidebar),它不会让子组件中定义标题。 – fortm