In rare situations, you may want to create a copy of a React element
当然这时候我还没用 Redux,Redux,Redux ,重要的事情说三遍,所以我传了个setTitle的回调函数过去,在children组件的componentDidMount调用setTitle设置header的title,此时对React略有失望,尽管用javascript来代替html——相比较其他拼命加自定义属性来扩展html标签的语义——的思路是创新的,但也正是以组件为单位的思路导致了这种丑陋的layout控制方法,大致的路由设计如下,
Layout组件的实现如下,
const Layout = React.createClass({ ... ... setTitle: function(title){ this.setState({title:title}); }
render:function(){
let childrenWithProps = React.Children.map(this.props.children, (child) => {
return React.cloneElement(child, { setTitle: this.setTitle.bind(this) });
});
return (
{childrenWithProps}
查看更多关于ReactJS应用的layout控制_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did111604