Search code examples
reactjsreact-routergatsbyreach-router

What is the equivalent of React router's useHistory hook in Reach router


I am in a gatsby project and I am trying to add query strings using 'qs' library and in the docs mentioned using:

const history = useHistory()

Then history.push(myStringParameter)

useHistory doesn't exist in Gatsby(Reach router) so what can I use instead?

Is there an equivalent in reach router? I have only really ever used React router.


Solution

  • You should try useNavigate from @reach/router

    If you need to navigate programmatically (like after a form submits), this hook gives you an API to do so with a signature like this: