Javascript 通过spread operator将所有道具传递给react组件是否会产生性能成本
目前,我发现自己编写了很多组件,如:Javascript 通过spread operator将所有道具传递给react组件是否会产生性能成本,javascript,reactjs,react-native,components,Javascript,Reactjs,React Native,Components,目前,我发现自己编写了很多组件,如: export default class MyComponent extends Component { constructor(props) { super(props) this.state = { someState1: 'something', someState2: 'something', someState3: 'something' } } render() {
export default class MyComponent extends Component {
constructor(props) {
super(props)
this.state = {
someState1: 'something',
someState2: 'something',
someState3: 'something'
}
}
render() {
return (
<ComponentOne prop1={this.someState1} {...this.props}/>
<ComponentTwo prop2={this.someState2} {...this.props}/>
<ComponentThree prop3={this.someState3} {...this.props}/>
)
}
}
导出默认类MyComponent扩展组件{
建造师(道具){
超级(道具)
此.state={
someState1:“某物”,
someState2:“某物”,
someState3:“某物”
}
}
render(){
返回(
)
}
}
更高级别的状态作为正常状态通过道具向下传递,并传播到子组件中
在某些情况下,我发现我正在将所有道具分散到每个子组件中,因为这比指定道具更快/更容易
因此,问题是:
这里有一个关于连接“太多”组件时的性能的非常有趣的讨论:这不是性能成本而是清晰性成本为什么不在您的案例中使用redux?它正是为了这个目的而制作的,所以你可以停止向不同的组件传递大量的道具。有限地使用redux或任何其他状态管理方法,这将很快失去控制也许是时候在我当前的应用程序中转移到一个状态管理库了,但是在我所有的项目中,我不太愿意使用它作为银弹。