Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

React Hook for pub-sub behavior using React Router.

License

NotificationsYou must be signed in to change notification settings

CharlesStover/use-react-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

versiondownloadsminzipped size

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.

Why Pub-Sub?

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.

Install

You must be usingreact-router andreact-router-dom v5.0.0 or greater.

  • npm install use-react-router or
  • yarn add use-react-router

Use

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>);};

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp