Life cycle of a class based component when connecting to the store

Stela Capsa
Jun 7, 2021

--

Instructor: Dakota Lee Martinez

Connect is a higher order component, a parent that wrapping the class component, that passes two functions along, MapStateToProps() and MapDispatchToProps(). The main purpose of this to function, is to add the props in to class based component that is wrapped by connect.

  1. MapStateToProps() and MapDispatchToProps() are called before componentDidMount. The data returned from those two functions are the props from the store returned when the first render is happening.
  2. ComponentDidMount is next after the first render, it dispatch an action creator, fetching the API, and then we use the THUNK to add a new dispatch storing the data in the store, and notify all the subscribed components. MapStateToProps() will be called again, to pass the props in the component, whenever a component receives new props it will re-render.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response