question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store not available in props/context of components rendered using react-router

See original GitHub issue

What I am rendering:

<Provider store={store}>
   <Router history={hashHistory}>
        <Route path='/' component={App}>
            <IndexRoute component={HomePage} onEnter={_ensureLoggedIn}/>
            <Route path="login" component={ SessionForm }/>
        </Route>
    </Router>
</Provider>

when attempting a sign in I am getting ‘Cannot read property ‘dispatch’ of undefined’ when calling this.context.store.dispatch

I threw a debugger and store is not present on this.props or this.context (SessionForm component).

I thought I tried everything from all the documentation on this subject I could find, still no help though

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alzapiedicommented, Aug 22, 2016

Excellent thank you Tim! and apologies for totally missing that part of the readme, I believed this particular functionality worked independently from connect

2reactions
timdorrcommented, Aug 22, 2016

Yes, but that’s removing a big benefit of having this library. You should use @connect instead like so: https://github.com/reactjs/react-redux/blob/master/docs/api.md#inject-todos-and-all-action-creators-addtodo-completetodo--as-actions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is React Router location props only available in Context?
While rendering a component using render props method you need get the router props as an argument in the callback function.
Read more >
How to protect your routes with React Context - Medium
We're going to take a look at how it works by building a protected route component. Context is about encapsulating state…
Read more >
location - React Router: Declarative Routing for React.js
The router will provide you with a location object in a few places: Route component as this.props.location; Route render as ({ location })...
Read more >
Provider | React Redux
Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a <Provider> , or pass a custom React...
Read more >
Passing Data Deeply with Context - React Docs
Context is not limited to static values. If you pass a different value on the next render, React will update all the components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found