React 属性 传播符号是否也传递给 children?
Does React property spread notation also pass on children?
这个return
语句中的React property spread notation是否...
render() {
return (
<Alert {...this.props}</Alert>
);
}
... 还向 Alert
组件提供所有 children 传递给拥有上述 render()
方法的当前组件?
或者我是否必须明确提供这样的 children?
render() {
return (
<Alert {...this.props}>{this.props.children}</Alert>
);
}
尝试后发现:是的,children也传了。
如前所述:object中的任何属性都将被传播。
这个return
语句中的React property spread notation是否...
render() {
return (
<Alert {...this.props}</Alert>
);
}
... 还向 Alert
组件提供所有 children 传递给拥有上述 render()
方法的当前组件?
或者我是否必须明确提供这样的 children?
render() {
return (
<Alert {...this.props}>{this.props.children}</Alert>
);
}
尝试后发现:是的,children也传了。
如前所述