npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rrc

v0.10.1

Published

React Router v4 helper components

Downloads

167

Readme

rrc = react router components

Travis

This module contains a number of components that can be used in conjuction with React Router v4. They are a somewhat random assortment of solutions to situations that I have either personally needed a component for or have seen others need a component for.

Installation

npm install --save rrc

UMD

You can also use the UMD version of rrc. This is useful if you are putting together a code snippet.

<script src="https://unpkg.com/rrc@0.10.0/umd/rrc.min.js"></script>

Note: The UMD builds are slightly bloated because they have to include React Router's <Route> component and matchPath function. This is because if you use the UMD build of react-router-dom instead of react-router, the ReactRouter global will not exist and rrc's imports will fail. The bloat is less than the extra data required to download the react-router build and this approach requires one less <script> tag.

Components

Read about the various components that are provided in the docs

These include:

<ConfigSwitch> and wrapSwitch

These both provide an alternative approach to React Router's <Switch> component. Intead of passing child elements to the <Switch>, both <ConfigSwitch> and the component returned by the wrapSwitch HOC take an array of route objects via the routes prop.

<ConfigSwitch routes={[
  { path: '/', exact: true, component: Home },
  { path: '/about' component: About }
]}/>

wrapSwitch in particular is useful for animations. It allows you to specify a component that will be used to wrap the matched route, providing better support for nested animations than is available with <Switch>

import { CSSTransitionGroup } from 'react-transition-group'

const CSSSwitch = wrapSwitch(CSSTransitionGroup)

const App = () => (
  <CSSSwitch
    transitionName='slide'
    component='div'
    routes={[
      { path: '/', exact: true, component: Home },
      { path: '/about' component: About }
    ]}
  />
)

<Status>

If you are doing server side rendering, the <Status> component offers an easy way to "render" a status. For example, if you have a "404" component that renders when no routes match, you can include a <Status> element inside of its render method so that your server can send the correct status code with the response.

const NoMatch = () => (
  <div>
    <Status code='404' />
    <h1>404</h1>
    <p>The page you were looking for was not found</p>
  </div>
)

The <Status> component will set a property on the context object that you pass to the <StaticRouter>, so all that you have to do is check the context object's status property.

const context = {}
const markup = renderToString(
  <StaticRouter context={context}>
    <App />
  </StaticRouter>
)

if (context.status === '404') {
  // ...
}

whenActive

The whenActive higher-order component creates <NavLink>-like components. While a <NavLink> can only create <a>s, the component returned by whenActive can render anything that you'd like.

// a button that can navigate
const Button = ({ to, ...rest}, { router }) => (
  <button
    type='button'
    onClick={(e) => {
      e.preventDefault()
      router.history.push(to)
    }}
    {...rest}
  />
)

const ActiveButton = whenActive({ className: 'i-am-active' })(Button)

// usage
const Controls = () => (
  <div>
    <ActiveButton to='/'>Home</ActiveButton>
    <ActiveButton to='/form'>Form</ActiveButton>
  </div>
)

This can also be used in place of the <NavLink> so that you don't have to specify the same "active" props for every location-aware link.

// with NavLink
const Links = () => (
  <div>
    <NavLink to='/one' activeClassName='the-active-class'>One</NavLink>
    <NavLink to='/two' activeClassName='the-active-class'>Two</NavLink>
    <NavLink to='/three' activeClassName='the-active-class'>Three</NavLink>
  </div>
)

// with whenActive
const ActiveLink = whenActive({ className: 'the-active-class' })(Link)
const Links = () => (
  <div>
    <ActiveLink to='/one'>One</ActiveLink>
    <ActiveLink to='/two'>Two</ActiveLink>
    <ActiveLink to='/three'>Three</ActiveLink>
  </div>
)

Related Projects:

  • qhistory - Add query object support to location objects
  • react-router-test-context - Simulate the context.router object. This can be useful if you are doing shallow testing of a component that needs to access React Router's context variables. Typically, though, you should just render your component inside of a <MemoryRouter>.