Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-react-router

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-react-router

React Hook for pub-sub behavior using React Router.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9K
decreased by-9.76%
Maintainers
1
Weekly downloads
 
Created
Source

use-react-router

useReactRouter is a React Hook that provides pub-sub behavior for react-router. Unlike the withRouter Higher-Order Component, useReactRouter will re-render your component when the location changes!

useReactRouter() returns the an object that contains the history, location, and match properties that would be passed as props by the HOC.

Why Pub-Sub?

Pub-sub behavior is a common request (that's commonly rejected) for the react-router package.

For users who adamently prefer pub-sub behavior over react-router's suggested alternatives, this package offers a solution.

A non-pub-sub React Hook is anticipated to eventually be included in the react-router package itself.

Install

You must be using react-router v4.4.0 or greater. At time of publication, you must install react-router@next in order to grab the 4.4.0 package.

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

Use

Import useReactRouter and use it as a React Hook.

import useReactRouter from 'use-react-router';

const MyPath = () => {
  const { history, location, match } = useReactRouter();
  return (
    <div>
      My location is {location.pathname}!
    </div>
  );
};

FAQs

Package last updated on 15 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc