- Notifications
You must be signed in to change notification settings - Fork30
React Hook for pub-sub behavior using React Router.
License
CharlesStover/use-react-router
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
useReactRouter is a React Hook that provides pub-sub behavior forreact-router.Unlike thewithRouter Higher-Order Component,useReactRouter will re-render your component when the location changes!
useReactRouter() returns an object that contains thehistory,location, andmatch properties that would be passed as props by the HOC.
A tutorial covering the design and development of this package can be found on Medium:How to Convert withRouter to a React Hook.
Pub-sub behavior is a common request (that's commonly rejected) for thereact-router package.
For users who adamently prefer pub-sub behavior overreact-router's suggested alternatives, this package offers a solution.
A non-pub-sub React Hook is anticipated to eventually be included in thereact-router package itself.
You must be usingreact-router andreact-router-dom v5.0.0 or greater.
npm install use-react-routeroryarn add use-react-router
ImportuseReactRouter and use it as a React Hook.
importuseReactRouterfrom'use-react-router';constMyPath=()=>{const{ history, location, match}=useReactRouter();return(<div> My location is{location.pathname}!</div>);};
About
React Hook for pub-sub behavior using React Router.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.