Storing Data in React
Data local to a component i.e. data which is not required to be shared across app or components:
Use component's local state
Use
this.state.onChange()
method to change the local state data and trigger a re-render of DOM
Use class level variable
e.g.
public someLocalVar
orprivate someLocalPrivateVar
Do not use class level variable for anything that you want to trigger re-rendeing of DOM
Data to be used across application or across multiple components:
Use Redux store and associate/connect your props variables with the global Redux store using the connect wrapper and a mapStateToProps function.
Last updated