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

react-fetch-flow

v0.1.7

Published

A framework for fetching initial data on page load

Readme

react-fetch-flow

A framework for fetching initial data on page load

Sandbox Demo

Why

Fetching data on page load in React Single Page Applications is not straightforward.

You must set loading states, use component lifecycle methods to fetch, while making sure you dont fetch data too often (or not enough) when the user navigates around your application.

The result is a bug prone implementation that you have to think through a lot to get right (and you shouldn't have to)!

This library solves this problem.

What

React Fetch Flow is a higher order component (HOC), middleware, and a simple reducer that takes care or setting loading states, client side routing behavior (as it relates to loading), and data fetching.

It follows a philosophy to make the implementation simple and intuitive for the user. This philosophy is that the user wants the most up to date data as they navigate throughout the application without having to refresh the page, unless they explicitly say so (for instance, the user presses back). So, react-fetch-flow will fetch data and set loading states whenever they push to browser history, and no other time.

This philosophy leads to a straightforward implementation that is intuitive for the user.

The redux version has more features than the simple react version. Because you can navigate across the application and keep state in the store, the user can update state on one route, then navigate, then if user presses 'back' they will get the previous state.

Use npm or yarn to add:

yarn add react-fetch-flow

npm install react-fetch-flow --save

How to integrate with only React

import React from 'react'
import { withFetchFlow } from 'react-fetch-flow'
import Loading from './Loading'
import { onRequest } from "./api";
 
@withFetchFlow({
  component: <Loading />,
  flag: "todos",
  onRequest //expects function that returns promise
})
class Todo extends React.Component {
  render(){
    return (
      <div>{this.props.todos.map(todo => <h2>todo.name</h2>)}</div>
    )
  }
}

How to integrate with Redux

There are 3 steps in order to get started:

1. Import Middleware

This manages when to set loading states. You will need to set up your request actions to have _REQUESTED and _SUCCESS in order for this to work properly.


import { fetchFlowMiddleware } from 'react-fetch-flow'

const middleware = [fetchFlowMiddleware] //add more if needed=

const store = createStore(
  rootReducer, // new root reducer with router state
  {},          // initialState
  applyMiddleware(...middleware)
)

2. Import Reducer

These will contain the loading states used by the HOC

import { combineReducers } from 'redux'
import {loadingReducer} from 'react-fetch-flow'

const rootReducer = combineReducers({
  //...other reducers
  loading: loadingReducer
})

3. Import Higher Order Component

Apply the HOC to your container components that you want to have fetching responsibility, generally the component that your react-router <Route /> component renders.


import React from 'react'
import { withReduxFlow } from 'react-fetch-flow'
import * as ACT from 'actions/actionTypes'
import Loading from './Loading'

@withReduxFlow({
  component: <Loading />, // loading component
  flag: "todo",                  // loading and loaded flag identifiers
  getFetchAction: props => ({ // put action that will be dispatched - follows _REQUESTED / _SUCCESS 
    type: ACT.INIT_TODOS_LIST_REQUESTED,
    payload: {
      todoId: props.match.params.todoId
    }
  })
})
@connect(({todos}) => {
  return {
    todo: todos.currentTodo
  }
})
class Todo extends React.Component {
 render(){
   return (
     <div>{this.props.todo.name}</div>
   )
 }
}