Skip to content

Instantly share code, notes, and snippets.

View bjgrosse's full-sized avatar

Benjamin Grosse bjgrosse

View GitHub Profile
@bjgrosse
bjgrosse / useNavigateTo.js
Last active January 22, 2020 19:45
React Router hook to navigate to a URL from inline event handler
import { useCallback } from "react";
import { useHistory } from "react-router-dom";
/**
* Uses history.push to navigate to the specified URL.
*
* @param {string} url
*
* Usage:
* <Button onClick={useNavigateTo("/start")}>Start</Button>
*/