There's a React component which its state is an array of svg elements. In each update only 1 element in this array may change. I want to benefit from wise and fast rendering provided by react. I use the following code to update the state and render.
render: function() {
return (
<div>
<svg width={Common.boardWidth} height={Common.boardHeight}>
{this.state.grid}
</svg>
</div>
);
}
_setNewState: function(index , newState){
this.setState(function(state){
return({
grid: state.grid[index].splice(index,1,newState)
});
});
},
_setNewState is called whenever we receive a new change in the state.
My question :
1.How can I replace an element in the array state to still benefit from fast rendering of React ? Do I benefit from fast rendering of react in the current approach ? or as the array changes, the whole thing will be rendered again ? even those elements which didn't change ?
2.What is the best approach in this case ? do we need to have an array of states instead of state that is an array ?
Note: Each element in this array is a SVG element with a unique key.