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.

Cannot read property 'getState' of undefined in routes.js

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
catamphetaminecommented, Jul 28, 2016

mm, that was a bug. I fixed it, try the latest version.

And it will be like this now: (new, correct)

export default function(store)

As opposed to this: (old, incorrect)

export default function({ store })

Post back if it works now. The store is not an actual store, but it has dispatch and getState if that’s sufficient

0reactions
catamphetaminecommented, Jul 28, 2016

Yes, 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?

Read more comments on GitHub >

github_iconTop 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 >
React TypeError: Cannot read property function of undefined
SET YOUR LIKE THERE ...
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 >

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