Playing with performance and seeing if saving the state of dynamically generated components on componentDidMount()
essentially creates performance improvement.
I see that {...this.props} only represents the props passed on the initial creation. Updates to the parent props does not trickle down on render() update.
This makes sense given React architecture but doesn't given JS referencing. Is it because this.props is merely an update of props, not an actual variable reference?
Musings: This would seem most performant method of dynamic components because they are generated only once. But it loses React's tracking ability I guess, why wouldn't React maintain understanding that these Views are grabbing {..this.props}.
// Inline Render
class MyDynamicViews extends React.Component {
state = {
views: []
}
componentDidMount() {
let json = [{
view: 1
}, {
view: 2
}, {
view: 3
}];
let views = json.map((view, i) => {
return <View key={i} {...this.props}>{view.i}</View>
});
this.setState({views});
}
render() {
return <View>{this.state.views}</View>
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…