Lifecycle events - KatyaHorton/Udacity-React-practice GitHub Wiki

Lifecycle events

Notes:

  • data should not be fetched in render()
  • render() - should not have anything asynchronous (!)

render():

  1. receives props
  2. renders them to UI

so, where do we make async requests?

Lifecycle events - special methods each component can have that allow us to hook into the views when specific conditins happen.

Lifecycle events (most common):

- componentWillMount

invoked immediately before the component is inserted into the DOM

- componentDidMount

invoked immediately after the component is inserted into the DOM

- componentWillUnmount

invoked immediately before a component is removed from the DOM

- componentWillReceiveProps

invoked immediately before the component is about to receive brand new props

To fetch external data from API - perfect case for component Lifecycle case