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
Its because the react-router context isn't set in that component. Since its the component that sets the context you could use useHistory in a sub-component, but not in that one.