我一周前就弄清楚了,这就是我想要的:
export default class ContainerComponent extends React.Component { constructor(props) { super(props); this.modifyChildren = this.modifyChildren.bind(this); } modifyChildren(child) { const className = classNames( child.props.className, {...otherClassses} ); const props = { className }; return React.cloneElement(child, props); } render() { return (<div> {React.Children.map(this.props.children, child => this.modifyChildren(child))} </div>); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)