实时预览:https://www.webpackbin.com/bins/-KoSqF5OB0IRtbBEi822
我正在尝试克隆和修改 React 元素对象。
我通过克隆 CSS 规则并将其添加到样式表来删除 React 元素的内联样式
我正在使用这个function
我想知道如何从 Element 的类访问 React Render 函数的返回值?
const Div = () => (<div></div>); // not working
const Div = (<div></div>); // working
const NewDiv = noInline(Div); // calling function
最佳答案
我相信要做到这一点,您需要在 render
函数中获取对元素的引用,并且该元素应该是组件子元素之一 - 因此遍历 this.props。 child
并找到您要查找的元素。像这样的事情:
render () {
let children = React.Children.toArray(this.props.children);
children.forEach((child) => doSomething(child))
}
关于javascript - 从 React 类修改 React 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978859/