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

reduxen-react-dom

v0.1.1

Published

React bindings for reduxen, a redux-first router

Downloads

12

Readme

reduxen-react-dom

React DOM bindings for reduxen.

Table of contents

API

Components

Link

Renders an <a /> tag that dispatches PUSH or REPLACE with the parsed to prop as the payload on click to update the url, and the state. Applies to as a href. Adds activeClassName if the current path matches with the Link's.

Must be embedded inside a <RouterProvider /> in the component tree.

Props:

  • to String url to navigate to (required to start with /, ? or #)
  • replace (optional) If true, the component dispatches REPLACE instead of PUSH. Defaults to false
  • children (optional) Children nodes to be rendered inside the <a />
  • style (optional) Style to be applied on the rendered <a />
  • className (optional) ClassName to be applied on the rendered <a />
  • activeClassName (optional) Adds the content of this prop if activePattern matches with the current path
  • activePattern (optional) Overrides the path checking of the Link. Can be used for navigation button (e.g. activePattern="/users/*") Defaults to to prop.

RouterProvider

Provides the given props in the context to the Link component.

Props:

  • router Router object from the state to pass down the hierarchy tree
  • dispatch The store's dispatch function
  • prefix (optional) Overrides default action namespace. Defaults to ROUTER__

Examples

With connect

index.jsx

import React from "react";
import ReactDOM from "react-dom";

import { connect, Provider } from "react-redux";
import { RouterProvider } from "reduxen-react-dom";

import configureStore from "./store/configureStore.js";
import App from "./view/App.js";

const store = configureStore();

const ConnectedRouterProvider = connect(({ router }) => ({ router }))(
  RouterProvider
);

ReactDOM.render(
  <Provider store={store}>
    <ConnectedRouterProvider>
      <App />
    </ConnectedRouterProvider>
  </Provider>,
  document.getElementById("react-root")
);

App.jsx

import React, { Fragment } from "react";

import { match } from "reduxen";

import { TodosScreen, TodoScreen, AboutScreen } from "./screens";

const App = ({ router }) => (
  <Fragment>
    {match("/todos", router.path) ? <TodosScreen /> : null}
    {match("/todos/:id", router.path) ? <TodoScreen /> : null}
    {match("/about", router.path) ? <AboutScreen /> : null}
  </Fragment>
);

const mapStateToProps = (state) => ({
  router: state.router
});

export default connect(mapStateToProps)(App);

Without connect

index.jsx

import React from "react";
import ReactDOM from "react-dom";

import { RouterProvider } from "reduxen-react-dom";

import configureStore from "./store/configureStore.js";
import App from "./view/App.js";

const store = configureStore();

const element = document.getElementById("react-root");

const renderApp = () => {
  const state = store.getState();
  const { dispatch } = store;

  ReactDOM.render(
    <RouterProvider router={state.router} dispatch={dispatch}>
      <App state={state} dispatch={dispatch} />
    </RouterProvider>,
    element
  );
};

store.subscribe(renderApp);

renderApp();

App.jsx

import React, { Fragment } from "react";

import { match } from "reduxen";

import { TodosScreen, TodoScreen, AboutScreen } from "./screens";

const App = ({ state, dispatch }) => {
  const { router } = state;

  return (
    <Fragment>
      {match("/todos", router.path) ? (
        <TodosScreen state={state} dispatch={dispatch} />
      ) : null}
      {match("/todos/:id", router.path) ? (
        <TodoScreen state={state} dispatch={dispatch} />
      ) : null}
      {match("/about", router.path) ? (
        <AboutScreen state={state} dispatch={dispatch} />
      ) : null}
    </Fragment>
  );
};

export default App;