Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-redux-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-redux-wrapper

Redux wrapper for Next.js

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
142K
decreased by-17.87%
Maintainers
1
Weekly downloads
 
Created

What is next-redux-wrapper?

The next-redux-wrapper package is a utility that helps integrate Redux with Next.js applications. It simplifies the process of setting up Redux in a Next.js environment by providing a higher-order component (HOC) that can wrap the Next.js App component, ensuring that the Redux store is properly initialized and available throughout the application.

What are next-redux-wrapper's main functionalities?

Store Initialization

This feature allows you to initialize a Redux store and wrap your Next.js application with it. The `createWrapper` function from next-redux-wrapper is used to create a wrapper that can be applied to the Next.js App component.

import { createStore } from 'redux';
import { createWrapper } from 'next-redux-wrapper';

const reducer = (state = { count: 0 }, action) => {
  switch (action.type) {
    case 'INCREMENT':
      return { ...state, count: state.count + 1 };
    default:
      return state;
  }
};

const makeStore = () => createStore(reducer);

export const wrapper = createWrapper(makeStore);

Server-Side Rendering (SSR) with Redux

This feature demonstrates how to use next-redux-wrapper to handle server-side rendering with Redux. The `getServerSideProps` function is wrapped with `wrapper.getServerSideProps`, allowing you to dispatch actions and access the Redux store on the server side.

import { wrapper } from '../store';

const Page = ({ count }) => (
  <div>
    <h1>Count: {count}</h1>
  </div>
);

export const getServerSideProps = wrapper.getServerSideProps((store) => async () => {
  store.dispatch({ type: 'INCREMENT' });
  return { props: { count: store.getState().count } };
});

export default Page;

Static Site Generation (SSG) with Redux

This feature shows how to use next-redux-wrapper for static site generation with Redux. The `getStaticProps` function is wrapped with `wrapper.getStaticProps`, enabling you to dispatch actions and access the Redux store during the build process.

import { wrapper } from '../store';

const Page = ({ count }) => (
  <div>
    <h1>Count: {count}</h1>
  </div>
);

export const getStaticProps = wrapper.getStaticProps((store) => async () => {
  store.dispatch({ type: 'INCREMENT' });
  return { props: { count: store.getState().count } };
});

export default Page;

Other packages similar to next-redux-wrapper

FAQs

Package last updated on 21 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc