ReactJS and immutability -
i've learning reactjs while now. 1 of thing puzzles me why reactjs uses immutability in many aspects props, elements etc. there specific reason this? philosophy behind this?
when try add new property props
i'm getting below error.
uncaught typeerror: can't add property me, object not extensible
react uses immutability obvious performance reasons. example
idea whenever setting state , dont mutate state clone part of , update state
for example
this.state = { entries: [1,2,3] }
you should do
this.state.setstate({ entries: this.state.entries.slice().push(9); //not this.state.entries.push(9) })
performance gains achieved when use shouldcomponentupdate
in shouldcomponentupdate can compare references , not due deep checking
shouldcomponentupdate(prevstate,newstate){ return prevstate.entries != newstate.entries }
Comments
Post a Comment