我正在学习本教程,导师做了类似的事情来解释高阶组件。
const aux = (props) => props.children;
export default aux;然后将这个导入到其他文件中,并将div标记替换为<Aux>标记。
现在,我很难理解这一点,因为我不太确定props.children到底做了什么(因为我们以前几乎没有在讲课中使用它)。
我在网上搜索了一两篇文章,但出于某种原因,他们的描述非常模糊。
有人能解释一下props.children的一般用法吗?
发布于 2018-04-25 17:55:02
发布于 2018-04-25 18:01:24
通常,每个组件的子组件实际上是一个数组。但是,当只有一个子组件时,props.children将是没有数组包装器的单个子组件。
因此,在本例中:const aux = (props) => props.children;将返回一个组件。
发布于 2018-04-25 20:30:32
该标准已被内置,以反应16.3和取代的只是<>。当您需要呈现多个组件时,您将使用它,但由于样式或任何其他原因,您不希望将它们包装为i。
例如:
<CustomeHeader />
<CustomTable />
<CustomFooter />不能在反应中呈现,但:
<>
<CustomeHeader />
<CustomTable />
<CustomFooter />
</>或者:
<aux>
<CustomeHeader />
<CustomTable />
<CustomFooter />
</aux>以上两种方法都是可行的。Aux或<>里面有什么?
https://stackoverflow.com/questions/50028445
复制相似问题