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.

this.props.history is not available in componentWillReceiveProps()

See original GitHub issue

I am trying to access

this.props.history

inside componentWillReceiveProps() but it is giving me undefined.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
WaqarHassancommented, Jan 15, 2019

Figured it out. Preact

preact-router gives route(${PATH}) to navigate.

React

this.props.history is available through react-router-dom by importing it and then wrapping exported component with withRouter to navigate.

Thanks @marvinhagemeister

1reaction
marvinhagemeistercommented, Jan 11, 2019

Can you show us the code where you’ll pass history to the component? It should work the same way in preact as it does in react. There is very likely something else going on that’s not related to the underlying framework but has to do with app code. Can you make a simple example in https://codesandbox.io/ where the issue can be reproduced?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router v4 this.props.history.push(...) not working
So I came to this question hoping for an answer but to no avail. I have used const { history } = this.props;...
Read more >
[Solved]-ReactJs this.props.history.push() is not working-Reactjs
Coding example for the question ReactJs this.props.history.push() is not working-Reactjs.
Read more >
location - React Router: Declarative Routing for React.js
location. Locations represent where the app is now, where you want it to go, or even where it was. It looks like this:...
Read more >
Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production ... componentWillReceiveProps (or UNSAFE_componentWillReceiveProps ) ...
Read more >
ReactJS UNSAFE_componentWillReceiveProps() Method
The componentWillReceiveProps() is invoked before our mounted React component receives new props. It is called during the updating phase of ...
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