Commit b509841f authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

Add useRouter hook (#6869)

This introduces the `useRouter` hook alternative to `withRouter`
parent 4b44778b
/* global window */ /* global window */
import React from 'react'
import _Router from 'next-server/dist/lib/router/router' import _Router from 'next-server/dist/lib/router/router'
import { RouterContext } from 'next-server/dist/lib/router-context'
const SingletonRouter = { const SingletonRouter = {
router: null, // holds the actual router instance router: null, // holds the actual router instance
...@@ -75,6 +77,10 @@ export default SingletonRouter ...@@ -75,6 +77,10 @@ export default SingletonRouter
// Reexport the withRoute HOC // Reexport the withRoute HOC
export { default as withRouter } from './with-router' export { default as withRouter } from './with-router'
export function useRouter () {
return React.useContext(RouterContext)
}
// INTERNAL APIS // INTERNAL APIS
// ------------- // -------------
// (do not use following exports inside the app) // (do not use following exports inside the app)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment