Cannot read property 'history' of undefined (useHistory hook of React Router 5)

前端 未结 6 1465
离开以前
离开以前 2020-12-17 08:14

I am using the new useHistory hook of React Router, which came out a few weeks ago. My React-router version is 5.1.2. My React is at version 16.10.1. You can find my code at

6条回答
  •  我在风中等你
    2020-12-17 08:28

    Note to other people that run into this problem and already have wrapped the component with Router component. Make sure that Router and the useHistory hook are imported from the same package. The same error can be thrown when one of them are imported from react-router and the other one from react-router-dom and the package versions of those packages don't match. Don't use both of them, read about the difference here.

提交回复
热议问题