0

In a React project Im using react-router-dom version 5.2.0. I want to navigate trough pages and components programmatically by calling history.push(path). It seems navigation works but I get a warning:

Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state

As I understand, the push functionality is setting state in render phase, but I don't know how to solve the problem.

Fcoder
  • 9,066
  • 17
  • 63
  • 100
  • Difficult to help without seeing the relevant code. Also take a look at [ReactJS: Warning: setState(…): Cannot update during an existing state transition](https://stackoverflow.com/questions/37387351/reactjs-warning-setstate-cannot-update-during-an-existing-state-transiti) – Yousaf Jul 13 '20 at 14:58
  • 1
    You may want to post the component code. You can use componentDidMount or componentDidUpdate depending on your needs if it's a class base component. useEffect if not. https://reactjs.org/docs/hooks-reference.html#useeffect – GitGitBoom Jul 13 '20 at 14:59

0 Answers0