State and Props
React lifecycle
- Based off the diagram, what happens first, the ‘render’ or the ‘componentDidMount’?
- What is the very first thing to happen in the lifecycle of React?
- Mounting in the “render phase” starting with constructor.
- Put the following things in the order that they happen: componentDidMount, render, constructor, componentWillUnmount, React Updates
- constructor, render, React updates, componentDidMount, componentWillUnmount
- What does componentDidMount do?
- Used immediately after a component is mounted to load anything using a network request or to initialize the DOM.
React State Vs Props
- What types of things can you pass in the props?
- Information unique to that component, but it should only be used for initial information.
- What is the big difference between props and state?
- Props are like the initial parameters while state can be updated from the initial props.
- When do we re-render our application?
- Every time the state changes or information is updated in the app.
- What are some examples of things that we could store in state?
- For a news website, the time since an article was posted or how many “likes” it has from social media interaction.