Last active
July 9, 2022 15:07
-
-
Save helloncanella/707b4241a7e4868d82e67b4b1ebd4a4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useRouter from "use-react-router" | |
import { matchPath } from "react-router-dom" | |
export default function useParams(path) { | |
const { location } = useRouter() | |
const { pathname } = location | |
const pattern = `(.*)?${path}` | |
const match = matchPath(pathname, { path: pattern }) || {} | |
return match.params | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment