Cannot read property 'getState' of undefined in routes.js
See original GitHub issueI am trying to use onEnter, passing store as parameter in code/client/routes.js. However I see TypeError: Cannot read property ‘getState’ of undefined. Seems store is function getState() instead on initial loading.
Here is the code is code/client/routes.js:
export default function({store})
{
console.log(store)
const routes =
(
<Route
component={RequireRole}
onEnter={RequireRole.onEnter(store)}>
<Route path="/" component={Layout} />
</Route>
)
return routes
}
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'getState' of undefined
I faced this error as I was not returning a function from store.js. Wrong : export const makeStore ...
Read more >TypeError: Cannot read property 'getState' of undefined #319
Error: TypeError : Cannot read property 'getState' of undefined at ... /node_modules/react-redux/lib/components/Provider.js:31:18 at Object.
Read more >cannot read properties of undefined (reading 'type') redux
I'd say it means you have used as argument to dispatch something that is not an action, i.e. has no type property. For...
Read more >How to Read React Errors (fix 'Cannot read property of ...
Cannot read property means the code was trying to read a property. This is a good clue! There are only a few ways...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
mm, that was a bug. I fixed it, try the latest version.
And it will be like this now: (new, correct)
As opposed to this: (old, incorrect)
Post back if it works now. The
store
is not an actual store, but it hasdispatch
andgetState
if that’s sufficientYes, I added an error message so that a user won’t be faced with
store is undefined
.Does your code work? Or are you still having issues?