【发布时间】:2018-04-17 07:53:45
【问题描述】:
过去几个小时我一直在研究如何渲染它,但我无法理解它。
const Test = props => (
<p>
{console.log(props)}
{props.children}
</p>
)
const changeColor = WrappedComponent => props => {
return class extends React.Component {
render() {
return (
<WrappedComponent style={{ color: props.color }} test="adasd">
{props.children}
</WrappedComponent>
)
}
}
}
const Temp = changeColor(Test)
当我去渲染它时,它告诉我Functions are not valid as a React child. 我将如何返回一个类组件,因为我需要访问状态。
【问题讨论】:
-
我认为你不能渲染
console.log -
@Andrew 感谢您的回复。如果我这样做
const Var = Temp("test")然后我得到它来渲染。这是否意味着我总是必须两次调用该函数,即Temp && Var确实要渲染类组件?如果是这样,那似乎有点太多了。
标签: reactjs higher-order-components