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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-queryparam-middleware

v1.3.1

Published

Simple redux middleware which will store (part of) the payload of specified actions in the url and is able to retrieve an initial state from the url

Readme

redux-queryparam-middleware

Simple redux middleware which will store (part of) the payload of specified actions in the url and is able to retrieve an initial state from the url

Installation

npm i -S redux-queryparam-middleware

How to use?

Use middleware

The middleware can be dropped into the redux middleware chain and will store the payload of one or more FSA complient actions in the url query parameters.

  import {applyMiddleware, createStore, compose} from 'redux';
  import createQueryparamMiddleware from 'redux-queryparam-middleware';

  const queryparamMiddleware = createQueryparamMiddleware({
    /** The types of the actions to listen for can be used for multiple **/
    types: ['MAP_MOVED'],
    /** The values to pick from the payload to store in the url. It will default to the entire flattened payload when nothing is specified **/
    include: ['center', 'bounds'],
    /** The specified queryparam values will be removed from the url when an action named in types is fired **/
    omit: ['bounds'],
    /** The transformer is an object which will modify the values of included parts of the payload. **/
    transformer: {
      center: (center) => convertToLatLngString(center),
    }
  });

  let store = createStore(
    rootReducer, // The main reducer
    initialState, // The state to load and prefill the redux store with
    compose(
    applyMiddleware(
      // All middleware
      queryparamMiddleware
    )
  );

Get initial state

Only using the middleware to store the state tree is not that usefull. That's why redux-queryparam-middleware also supports initialising the state from url parameters.

  import {applyMiddleware, createStore, compose} from 'redux';
  import createQueryparamMiddleware, {getQueryparamState} from 'redux-queryparam-middleware';

  const queryparamMiddleware = createStorageMiddleware({
    types: ['MAP_MOVED'],
    include: ['center', 'zoom'],
    omit: ['bounds'],
    transformer: {
      center: (center) => convertToLatLngString(center),
    },
  });

  const initialState = getQueryparamState({
    /** The query params to read from the url and use as part of the initialState **/
    keys: ['center', 'zoom', 'bounds'],
    /** The transformer is an object which will modify the values of specific query  params **/
    transformer: {
      center: (center) => convertToLatLng(center),
      bounds: (bounds) => convertToBounds(bounds),
    },
    /** You need to specify a reducer to add the state to **/
    reducer: 'map',
    /** The state to apply the query params state to **/
    state: initialState,
  });

  let store = createStore(
    rootReducer, // The main reducer
    initialState, // The state to load and prefill the redux store with
    compose(
      applyMiddleware(
        // All middleware
        queryparamMiddleware
      )
    )
  );

Reference

queryparamMiddlewareTransformer

This is used to transform the request to the right right queryparams

Type: Object

createQueryparamMiddleware

This middleware for redux will store a slice of the redux state in queryparams

Parameters

  • settings any Object containing all configuration for the queryparam middleware
    • settings.types A collection of action types to listen to
    • settings.include Properties of the payload objects of the types to store in the url
    • settings.omit A collection of properties to remove from the url when an action runs
    • settings.transformer An object containing methods to transform certain payload values

Returns any The final result when all reducers have been run

getQueryparamState

This will get the current state information from the queryparams

Parameters

  • settings any An object containing the settings to retreive the state from the queryparams
    • settings.keys The keys to read from the url
    • settings.transformer An object containing methods to transform certain querparam values
    • settings.reducer The reducer to update in the store
    • settings.state The initial state to modify

Returns Object An object containing the needed information in the right format

getQueryparamData

This will get an object containing the data contained in the queryparams

Parameters

  • settings any An object containing the settings to retreive the state from the queryparams
    • settings.keys The keys to read from the url
    • settings.transformer An object containing methods to transform certain querparam values

Returns Object An object containing the needed information in the right format