- Based off the diagram, what happens first, the
‘render’or the‘componentDidMount’?
render
- What is the very first thing to happen in the lifecycle of React?
constructor functions get 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
componentDidMountdo?
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().
- What types of things can you pass in the props?
- What is the big difference between props and state?
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.
- When do we re-render our application?
whenever a state is changed (typically something that the user has done).
- What are some examples of things that we could store in state?
local variables like a counter, if we're manipulating information within a component, then we need to use state.
- Google Bard and ChatGPT