我需要从儿童中删除道具。反应 - 从儿童中删除道具
我有一个容器元素,它使用它的孩子的属性来对孩子进行一些增强。在渲染前应该将该属性从小孩中移除。
<AsyncContainer>
<Button onClick={this.asyncStuff} asyncHandler="onClick"/>
</AsyncContainer>
应该在呈现之前从按钮中删除asyncHandler属性。
AsyncContainer使用React.cloneElement(child, properties)
。
我已经尝试nulling asyncHandler属性,将其设置为undefined并从child.props删除属性。似乎不可能再次摆脱这个属性。
'props',因此不能由组件自身来改变。父母必须修改'prop',然后将其传递给组件。 – Dan
你不能对儿童道具做任何事情,因为它们是只读的:https://facebook.github。io/react/docs/components-and-props.html#props-are-read-only –
也许你可以克隆孩子并以某种方式替换属性对象? – AnAmuser