Skip to content

Instantly share code, notes, and snippets.

@HaNdTriX
Last active February 6, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HaNdTriX/37cf6d69a01865364b971652c9ee173e to your computer and use it in GitHub Desktop.
Save HaNdTriX/37cf6d69a01865364b971652c9ee173e to your computer and use it in GitHub Desktop.
React-Router hooks usage
import { useContext } from 'react'
import { __RouterContext as RouterContext, matchPath } from 'react-router-dom'
export default function useRouter (options = {}) {
const context = useContext(RouterContext)
const location = options.location || context.location
const match = options.path
? matchPath(location.pathname, options)
: context.match
return { ...context, location, match }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment