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 🙏

© 2026 – Pkg Stats / Ryan Hefner

redux-suspenders

v1.0.7

Published

Tie into React's Suspense API with Redux

Readme

redux-suspenders

npm NpmLicense

Tie into React's Suspense API with a Redux app

Setup

npm install --save redux-suspenders

Usage

Redux-suspenders offers a single function as the default export, called createResource.

Defining the resource

import createResource from 'redux-suspenders';

const fetchGithubAccount = username => fetch(`https://github.com/users/${username}`)
    .then(response => response.json());

//Assume some reducer listens for this action
const setUser = user => ({
  type: 'SET_USER_DATA',
  payload: user
});

const loadData = (props) => fetchGithubAccount(props.username);
const selectData = (state, props) => state.users[props.username]
const updateData = (response, props) => setUser(response);

//The result of createResource() is a React.Component
export const GithubUserResource = createResource(
  loadData,   //Must either return a Promise directly, or return a Promise when dispatched
  selectData, //Should return falsy value when data doesn't exist
  updateData  //Should update the data read by the selector
);

Consuming the resource

Any Resource accepts a function as a child, which will only get called once there is data in the redux store. All props given to your Resource will be provided as the last argument to all of the functions passed into the createResource call.

  import React, { Suspense } from 'react';
  import { GithubUserResource } from '../src/githubUserResource';
  
  const ShowUserInfo = ({ username }) => {
    return (
      <Suspense fallback={'Loading...'}>
        <GithubUserResource username={username}> 
          {user => (
            {/* Renders only when data is loaded into redux, otherwise renders Suspsense's fallback */}
            <div>{JSON.stringify(user, null, 2)}</div>
          )
        </GithubUserResource>
      </Suspense>
    )
  }

Movitivation

React Suspense is an awesome feature, and with it, a lot of examples show off simple-cache-provider, or even react-cache as ways to asynchronously load data inside of render functions. If you're working on an idiomatic (or large) Redux application, however, utilizing these new APIs can feel either like a lot of work, or a lot of best practices will be broken (side-effects in renders, storing data in external caches, maybe even having to sync the cache with Redux, etc).

The good news is, if you're using Redux, you already have a client-side cache! This little library hopes to make utilizing Suspense for loading data easy for Redux applications.

Plus, it uses a render prop! So no side effects are necessary in your components!

Considerations

The load function that you provide to createResource gets ran with any props given to the Resource component. If the result of load is not a promise, it will be dispatched, which must then return a Promise.

  //A redux-thunk example
  const loadSomeData = (resourceProps) => (dispatch, getState) => {
  let request;
  
  //...build request
  dispatch(({ type: 'SENDING_REQUEST' }));
  
  return fetch(request) //returns a Promise;
}