reading-notes

Class 301.02

Notes

Readings

React lifecycle

  1. Based off the diagram, what happens first, the ‘render’ or the ‘componentDidMount’?

    render

  2. What is the very first thing to happen in the lifecycle of React?

    constructor functions get called

  3. Put the following things in the order that they happen: componentDidMount, render, constructor, componentWillUnmount, React Updates
    1. constructor
    2. render
    3. componentDidMount
    4. React Updates
    5. componentWillUnmount
  4. What does 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().

React State Vs Props

  1. What types of things can you pass in the props?
  2. 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.

  3. When do we re-render our application?

    whenever a state is changed (typically something that the user has done).

  4. 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.

Things I want to learn more about

References