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

@truefit/bach-react-router

v2.1.0

Published

connect your composed components to react-router

Downloads

53

Readme

@truefit/bach-react-router

Overview

This set of enhancers exposes the hooks from react router to the bach compose chain.

Installation

npm install @truefit/bach-react-router @truefit/bach

or

yarn add @truefit/bach-react-router @truefit/bach

Enhancers

withHistory

Gives you access to the history instance that you may use to navigate.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withHistory} from '@truefit/bach-react-router';
import {History} from 'history';

type Props = {
  history: History;
  handeClick: () => void;
}

const Component = ({handleClick}: Props) => (
  <div>
    <button onClick={handleClick}>
      Click Me
    </button>
  </div>
);

export default compose<Props>(
  withHistory(),

  withCallback<Props>('handleClick', ({history}) => () => {
    history.push('/home');
  }),
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withHistory} from '@truefit/bach-react-router';

const Component = ({handleClick}) => (
  <div>
    <button onClick={handleClick}>
      Click Me
    </button>
  </div>
);

export default compose(
  withHistory(),

  withCallback('handleClick', ({history}) => () => {
    history.push('/home');
  }),
)(Component);

withLocation

Returns the location object that represents the current URL. You can think about it like a useState that returns a new location whenever the URL changes.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withLocation} from '@truefit/bach-react-router';
import {Location} from 'history';

type Props = {
  location: Location;
}

const Component = ({location}: Props) => (
  <div>
    {location.pathname}
  </div>
);

export default compose(
  withLocation()
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withLocation} from '@truefit/bach-react-router';

const Component = ({location}) => (
  <div>
    {location.pathname}
  </div>
);

export default compose(
  withLocation()
)(Component);

withParams

Returns an object of key/value pairs of URL parameters

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withParams} from '@truefit/bach-react-router';

type Props = {
  slug: string;
}

const Component = ({slug}: Props) => (
  <div>
    {slug}
  </div>
);

export default compose(
  withParams(['slug'])
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withParams} from '@truefit/bach-react-router';

const Component = ({slug}) => (
  <div>
    {slug}
  </div>
);

export default compose(
  withParams(['slug'])
)(Component);

withRouteMatch

Attempts to match the current URL in the same way that a would

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withRouteMatch} from '@truefit/bach-react-router';
import {match} from 'react-router';

type Props = {
  match: match;
}

const Component = ({match}: Props) => (
  <div>
    {match.path}
  </div>
);

export default compose(
  withRouteMatch('/blog/:slug')
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withRouteMatch} from '@truefit/bach-react-router';

const Component = ({match}) => (
  <div>
    {match.path}
  </div>
);

export default compose(
  withRouteMatch('/blog/:slug')
)(Component);