Notes on State and Props
React lifecycle
- Based off the diagram, what happens first, the ‘render’ or the ‘componentDidMount’?
render
happens first, then React updates DOM and refs, and THEN componentDidMount
happens.
- What is the very first thing to happen in the lifecycle of React?
The constructor is called.
- Put the following things in the order that they happen: componentDidMount, render, constructor, componentWillUnmount, React Updates
constructor -> render -> componentDidMount -> React Updates -> componentWillUnmount
- What does componentDidMount do?
It allows for loading of anything that uses a network request or initializes the DOM. It is invoked right after component mounting.
React State Vs Props
- What types of things can you pass in the props?
Things you want to pass to a function (such as a count, or a display with title and subtitle).
- What is the big difference between props and state?
State is handled inside of a component, and props are handled outside of a component and then passed in.
- When do we re-render our application?
When we change the state.
- What are some examples of things that we could store in state?
For things that need to change in application based on user input. For example, inside of a form, state is needed to store what users are updating form input values to so it can be re-rendered. Things that aren’t static (i.e. data that is meant to change over time and use).
Things I want to know more about
The React lifecycle article talked about how componentDidMount is a good place for put “subscriptions”, but I’m confused as to what that means here.