React Lifecycle & React State vs. Props

My reading notes for Code Fellows


React Lifecycle & React State vs. Props

React lifecycle

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? Mounting

Put the following things in the order that they happen: componentDidMount, render, constructor, componentWillUnmount, React Updates

  1. constructor
  2. render
  3. React Updates
  4. componentDidMount
  5. componentWillUnmount

What does componentDidMount do? Connects to APIs

React State Vs Props

What types of things can you pass in the props? Variables Initial values for things Titles/Subtitles

What is the big difference between props and state? Props are passed into a component. State is handled inside of that comnponent, and it can be updated inside the component. Props are handled outside of that component, and must be updated outside of the component.

When do we re-render our application? When one changes the state in an application, the application will be re-rendered.

What are some examples of things that we could store in state? When a user interacts with the application, the changes will need to be stored in state so they can be re-rendered. i.e., when a visit to the app happens, a counter increments by one. In this case the new count will be stored in state.

Forms need to be updated by the user, so state is used to store the values that are being passed by the user.