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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cdmbase/redux-data-router

v1.0.10

Published

**`redux-data-router`** is a clean-room spiritual successor to projects like **redux-first-history**.

Downloads

388

Readme

CI npm version

⚙️ redux-data-router 🔩

redux-data-router is a clean-room spiritual successor to projects like redux-first-history.

You only need to bring your React Router v6 data router, no need to manage a history object (or use UNSTABLE_ methods :smile:)

Usage with router

import {createEnhancer, reducer} from 'redux-data-router';

// Create your data router like normal.
const router = createBrowserRouter(routes);
// Install the router reducer and enhancer.
const store = configureStore(
  reducer: {router: reducer}, // Install the reducer at the 'router' slice by default.
  enhancers: [createEnhancer(router)],
);

Redux is now connected to React Router! Yes, that's it.

Backwards-compatible

Effort has been made to keep the history action types working. redux-data-router exports all the actions you know and love:

dispatch(back());
dispatch(forward());
dispatch(go(2));
dispatch(goBack(2));
dispatch(goForward());
dispatch(push('/', state || {}));
dispatch(replace('/about'));

There is a new navigate action that is more semantically in line with how the modern router actually works:

dispatch(navigate('/about'));
dispatch(navigate('/about', {replace: true}));
dispatch(navigate(2));

Under the hood

History actions are casted to an equivalent navigate action. See: actions.js

Does this support time-travelling?

Yes. :grin: Router navigation is a side-effect of every location state change.

Configuration

createEnhancer takes an optional options object after your router:

{
  // The key used for the router slice.
  key: 'router',
}

For example, the introduction could have been configured differently for your unique state structure:

const store = configureStore(
  reducer: {FOO_BAR: reducer},
  enhancers: [createEnhancer(router, {key: 'FOO_BAR'})],
);

How it works

Up to now, libraries have been handling a history object to synchronize Redux state with React Router. This approach is no longer practical with current (February 2024) React Router data router semantics.

All is not lost, however! Instead of history.listen, we have a new API: router.subscribe. redux-data-router subscribes to changes through this channel to continuously synchronize the Redux state with the router state.

Is this a real single source of truth?

Probably not. React Router's internals aren't always easy to get into, and there may even be issues with the approach taken here. If e.g. the internal updateState API were made public, we might be able to become a true SSOT.

Contributing

npm ci
npm run lint && npm run test