The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Redux: Passing the Store Down Implicitly via Context

Redux: Passing the Store Down Implicitly via Context

7:56
Learn how to make the store object available to all components by using the advanced React feature called “context”.
Watch this lesson now
Avatar
egghead.io

Learn how to make the store object available to all components by using the advanced React feature called “context”.

Avatar
GreenAsJade

I see this sort of thing in code I'm working with:

import {Provider} from 'react-redux'

and

return (
     <Provider store={store}>
        <div>
           <ReduxRouter />
           <DevTools />
        </div>
     </Provider>
  )

There's no declaring of contextTypes.

It would be nice if this video alluded to what that might be about, even if it is a more advanced topic.

Is it legit?

In reply to egghead.io
Avatar
GreenAsJade

This seems like a marginal gain: removing some small "passing down" overhead and replacing it with many lines of contextType declaration that can fail silently.

What is the thinking there?

In reply to egghead.io
Avatar
GreenAsJade

Hah - I see the next lesson covers this. Still seems like marginal gains, to have to have all those contextTypes etc declared.

In reply to GreenAsJade
Avatar
Jiwon

I do not understand why you declared it twice.

const { store } = this.context;

like this
'''
componentDidMount() {
const { store } = this.context;
}

render() {
const { store } = this.context;
}
'''

Avatar
Joe Talarovich

Life cycle methods.
componentDidMount is only called on the first render. (Component is receiving the state at time of render)
render is called each time the state changes, each time the state changes you will have access to the new state.

In reply to Jiwon
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?