‘render’
or the ‘componentDidMount’
?
render
constructor functions get called
componentDidMount
, render
, constructor
, componentWillUnmount
, React Updates
- constructor
- render
- componentDidMount
- React Updates
- componentWillUnmount
componentDidMount
do?
It is invoked immediately after a component is mounted. If I need to load anything using a network request or initialize the DOM, it should go here. This method is a good place to set up any subscriptions. If I do that, don’t forget to unsubscribe in componentWillUnmount().
props: these are like arguments to a function; it’s something handed to a component (e.g. the initial counter value, eg = 0). Any changes must be handled outside of the component state: this is something inside of a component (e.g. the current count). When you change the state, it will be re-rendered (doesn’t apply to props because nothing can change within props). It’s there to be re-rendered when the user has done something.
whenever a state is changed (typically something that the user has done).
local variables like a counter, if we’re manipulating information within a component, then we need to use state.