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-saga-fetch

v0.3.0

Published

A saga that reduces http request duplication

Readme

redux-saga-fetch Build Status codecov

A saga that helps reduce http duplication when writing redux-saga code.

Getting Started

Install

$ npm install --save redux-saga-fetch

or

$ yarn add redux-saga-fetch

Usage Example

Let's say you read the redux-saga readme, and start implementing the 3 kinds of actions USER_FETCH_REQUESTED,USER_FETCH_SUCCEEDED and USER_FETCH_FAILED. Then you start to create the userSaga. You start copy/pasting this userSaga for all of your objects, and start thinking "This is not very DRY", and maybe even give up redux-saga. redux-saga-fetch is here to save the day!

Let's create a simple actions file for now. This will use the same actions from the redux-saga readme.

actions.js

import { get } from 'redux-saga-fetch';

// this is where the magic happens
// the `get` is an action creator, that takes a url and 2 important functions
// success: an action creator that can return a Promise, or an action
// fail: an action creator that catches any errors, either in fetch or in the
//       success action creator
export function userFetchRequested(userId) {
    return get(`/users/${userId}`, {
        success: response => response.json().then(userFetchSucceeded),
        fail: userFetchFailed
    })
}

export function userFetchSucceeeded(user) {
    return { type: 'USER_FETCH_SUCCEEDED', user: user }
}

export function userFetchFailed(e) {
    return { type: 'USER_FETCH_FAILED', message: e.message }
}

This is the main.js taken from the redux-saga readme.

main.js

import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
+import fetchSaga from 'redux-saga-fetch'

import reducer from './reducers'
import mySaga from './sagas'

// create the saga middleware
const sagaMiddleware = createSagaMiddleware()
// mount it on the Store
const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware)
)

// then run the saga
-sagaMiddleware.run(mySaga)
+sagaMiddleware.run(fetchSaga)

// render the application

And there you have it! redux-saga-fetch removes the need to write an entire saga for basic use cases.

Starting other actions on completion

If you have a more complex use case where you need a successful action to start some other asynchronous actions, you can still use redux-thunk for that.

Add the thunk middleware to your store.

main.js

import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
+import thunk from 'redux-thunk'
import fetchSaga from 'redux-saga-fetch'

import reducer from './reducers'
import mySaga from './sagas'

// create the saga middleware
const sagaMiddleware = createSagaMiddleware()
// mount it on the Store
const store = createStore(
  reducer,
-  applyMiddleware(sagaMiddleware)
+  applyMiddleware(sagaMiddleware, thunk)
)

// then run the saga
sagaMiddleware.run(fetchSaga)

// render the application

Then update your actions.js file to return a thunk for the USER_FETCH_SUCCEEDED rather than a single action.

actions.js

-export function userFetchSucceeeded(user) {
-    return { type: 'USER_FETCH_SUCCEEDED', user: user }
-}
+export function userFetchSucceeded(uesr) {
+    return function(dispatch) {
+        dispatch({ type: 'USER_FETCH_SUCCEEDED', user: user })
+        // start kicking off some other actions
+        dispatch({ type: 'FETCH_TODOS_FOR_USER', user: user })
+        dispatch({ type: 'FETCH_FRIENDS_FOR_USER', user: user });
+    }
+}

Documentation

All the options supported by the fetch api are supported. Just pass them in as extra arguments to the second parameter.

Examples