next-redux-store
Advanced tools
Weekly downloads
Readme
Next integration with Redux.
Features:
npm i next-redux-store
import { AppProps } from 'next/app';
import { StoreProvider } from 'next-redux-store';
import { makeStore } from 'modules/makeStore';
export default function _App(appProps: AppProps<any>) {
const { Component, pageProps } = appProps;
return (
<StoreProvider makeStore={makeStore} appProps={appProps}>
<Component {...pageProps} />
</StoreProvider>
);
}
NOTE: makeStore must accept preloadedState as an argument. See example.
import { createGetInitialProps } from 'next-redux-store/server';
import { makeStore } from 'modules/makeStore';
const getInitialState = async (ctx, appProps) => {
const store = makeStore();
// Fill the store considering the App props and Document context
// See example (https://github.com/fakundo/next-redux-store/blob/master/packages/docs/pages/_document.tsx#L14)
return store.getState();
}
export default class _Document extends Document {
static getInitialProps = createGetInitialProps(getInitialState);
render() {
...
}
}
import { serverSideState } from 'next-redux-store/server';
export const getStaticProps = async () => {
const store = makeStore();
// Fill the store
const initialState = store.getState();
return {
props: {
...serverSideState(initialState),
},
};
}
import { StoreProvider } from 'next-redux-store'
import { ProviderProps } from 'react-redux';
interface StoreProviderProps extends Omit<ProviderProps, 'store'> {
appProps: AppProps<any>;
makeStore: (preloadedState: any | undefined) => any;
}
declare class StoreProvider extends Component<StoreProviderProps> {}
import { createGetInitialProps } from 'next-redux-store/server';
Function createGetInitialProps creates a function that returns initial props for the Document, providing initial state of the store for the App.
type CreateInitialState = (ctx: DocumentContext, appProps: AppProps<any> | undefined) => any;
const createGetInitialProps: (createInitialState: CreateInitialState) => (ctx: DocumentContext) => DocumentInitialProps;
Function createInitialState accepts Document context and App props as parameters and returns initial state of the store.
import { serverSideState } from 'next-redux-store/server';
Function serverSideState accepts state of the store and returns page props.
import { HYDRATE } from 'next-redux-store';
HYDRATE returns name of the hydration action.
MIT
FAQs
Next integration with Redux
The npm package next-redux-store receives a total of 785 weekly downloads. As such, next-redux-store popularity was classified as not popular.
We found that next-redux-store demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.