UNPKG

use-query-params

Version:

React Hook for managing state in URL query parameters with easy serialization.

23 lines (22 loc) 512 B
import { useHistory, useLocation } from "react-router-dom"; const ReactRouter5Adapter = ({ children }) => { const location = useLocation(); const history = useHistory(); const adapter = { replace(location2) { history.replace(location2.search || "?", location2.state); }, push(location2) { history.push(location2.search || "?", location2.state); }, get location() { return history.location; } }; return children(adapter); }; export { ReactRouter5Adapter };