Sono nuovo nella libreria React.js e stavo esaminando alcuni tutorial e mi sono imbattuto in:
this.setStatethis.replaceState
La descrizione fornita non è molto chiara (IMO).
setState is done to 'set' the state of a value, even if its already set
in the 'getInitialState' function.
Allo stesso modo,
The replaceState() method is for when you want to clear out the values
already in state, and add new ones.
Ho provato this.setState({data: someArray});seguito da this.replaceState({test: someArray});e poi li console.logged e ho scoperto che statela società aveva sia datae test.
Poi, ho provato this.setState({data: someArray});seguito da this.setState({test: someArray});e poi li console.logged e ho scoperto che stateancora una volta aveva sia datae test.
Allora, qual è esattamente la differenza tra i due?