State and Props

State and Props

React lifecycle

React State Vs Props

React Lifecycle

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

  2. What is the very first thing to happen in the lifecycle of React? - the constructor for a React component is called

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

  4. What does componentDidMount do? - If you need to load anything using a network request or initialize the DOM, it should go here. A good place to set up any subscriptions.

React State vs Props

  1. What types of things can you pass in the props? - arguments to a function, they’re what you want to initialize your component to or what you want your component to render like. You can pass the initial count for a counter, the title and subtitle

  2. What is the big difference between props and state? - props you pass into a component, state is handled inside of that component and props are handled outside of the component

  3. When do we re-render our application? - when you change the state inside of your application

  4. What are some examples of things that we could store in state? - with forms, you can use state to store what the user is updating the values to and what they’re changing that value to and so on.

Things I want to know more about

Return home