Code Fellows Notes
React lets you define components as classes or functions. The methods that you are able to use on these are called lifecycle events. These methods can be called during the lifecycle of a component, and they allow you to update the UI and application states.
render
constructor()
is called
constructor
render
React Updates
componentDidMount
componentWillUnmount
componentDidMount
do?The componentDidMount()
method allows us to execute the React code when the component is already placed in the DOM (Document Object Model). This method is called during the Mounting phase of the React Life-cycle i.e after the component is rendered.
When you create a component inside of react and you want to render it you’re going to pass it the props you want to give to it. Kind of like things you pass through a function, what you want to initialize your component, or what you want your component to render like.
State is something inside of a component versus props you pass into a component (handled inside versus outside)
State is there when you need to actually rerender and update your application based on something the user has done. So if you want to change something in your application you need to store that in state.
Props are useful when you want to display some information inside of a component without hard coding. Essentially like a variable to a function or like things you would pass to a constructor.
When the state is changed.
Things handled only inside of the component. Or things that are dynamic - such as items that will update with user input.