根据 ESLINT 规则 no-children-prop
When using JSX, the children should be nested between the opening and closing tags. When not using JSX, the children should be passed as additional arguments to React.createElement
这只是一种风格建议,还是会产生真正的损害?
最佳答案
这似乎更像是一种风格建议,也可以防止您射中自己的脚。
如果你有一个组件:
<Component children="foo">bar</Component>
并在组件中做
return (
<div>
{this.props.children}
</div>
)
你最终会得到
bar
作为 this.props.children
而不是 foo
但只要这会破坏任何 react 或造成“损坏”我没有发现这样的证据,这里有一个冗长的讨论 https://github.com/airbnb/javascript/issues/1089#issuecomment-250640742
说明相同。
关于reactjs - 为什么不应该将 child 作为 Prop 传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42982416/