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

@fifi98/next-redux

v1.0.1

Published

Package for setting up Redux with Next.js with ease.

Readme

@fifi98/next-redux

Package for setting up Redux with Next.js with ease.

This package is inspired by next-redux-wrapper but with a few key features in mind:

  • 🔥 super easy to setup
  • 📦 very lightweight

What is it used for?

Sometimes you might want to fetch data in your Next.js application server-side using one of Next's data fetching methods (getInitialProps, getServerSideProps or getStaticProps). By doing that you also might want to preload that fetched data server-side directly to your Redux store. This package makes it super easy to do exactly that!

How does it work?

You will have a server side instance of your Redux store on which you can dispatch actions. Redux's job on the server side is to provide the initial state of our app. That server side store will than be passed to the client side and will hydrate the client side store with your server side data - all that without a delay or flicker on the UI which usually occurs if you are hydrating your client side store by dispatching an action in useEffect hook.

🛠️ Installation

yarn add @fifi98/next-redux react-redux

👨‍💻 Usage

First create your Redux store, for example in store.ts file.

import { AnyAction, combineReducers, configureStore } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import { HYDRATE } from "@fifi98/next-redux";

import facts from "./facts";

const combinedReducer = combineReducers({ facts });

const reducer = (state: ReturnType<typeof combinedReducer> | undefined, action: AnyAction): ReturnType<typeof combinedReducer> => {
  if (action.type === HYDRATE) {
    return { ...state, ...action.payload };
  } else {
    return combinedReducer(state, action);
  }
};

export const store = configureStore({ reducer });

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

The next step is to wrap your _app.tsx with the StoreProvider component which accepts two props - store which we created in the previous step and state - the data which is going to be passed from your server side data fetching methods.

import { store } from "../store";

import { StoreProvider } from "@fifi98/next-redux";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <StoreProvider store={store} state={pageProps.state}>
      <Component {...pageProps} />
    </StoreProvider>
  );
}

getInitialProps

import { createStore } from "@fifi98/next-redux";

MyApp.getInitialProps = async (): Promise<AppInitialProps> => {
  const { getState, dispatch } = createStore(store);

  const data = await fetch("https://catfact.ninja/fact").then((r) => r.json());

  dispatch(setFact(data.fact));

  return {
    pageProps: {
      state: getState(),
    },
  };
};

getServerSideProps

import { createStore } from "@fifi98/next-redux";

export const getServerSideProps: GetServerSideProps = async () => {
  const { getState, dispatch } = createStore(store);

  const data = await fetch("https://catfact.ninja/fact").then((r) => r.json());

  dispatch(setFact(data.fact));

  return {
    props: {
      state: getState(),
    },
  };
};

getStaticProps

import { createStore } from "@fifi98/next-redux";

export const getStaticProps: GetStaticProps = async () => {
  const { getState, dispatch } = createStore(store);

  const data = await fetch("https://catfact.ninja/fact").then((r) => r.json());

  dispatch(setFact(data.fact));

  return {
    props: {
      state: getState(),
    },
  };
};

🎥 Demo

The demo app is available in the demo folder