Skip to content

Instantly share code, notes, and snippets.

@andycarrell
Created November 7, 2019 02:48
Show Gist options
  • Save andycarrell/e3a94f3e6df39bed444eb5a098963868 to your computer and use it in GitHub Desktop.
Save andycarrell/e3a94f3e6df39bed444eb5a098963868 to your computer and use it in GitHub Desktop.
import { useCallback } from "react";
import { useHistory } from "react-router-dom";
function useNavigateTo(defaultTo, method = "push") {
const history = useHistory();
return useCallback((to = defaultTo) => history[method](to), [
history,
method,
defaultTo,
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment