Socket
Socket
Sign inDemoInstall

next-redux-store

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-redux-store - npm Package Compare versions

Comparing version 0.0.14 to 0.1.0

LICENSE

2

dist/createGetInitialProps.js

@@ -1,2 +0,2 @@

"use strict";var g=Object.create;var P=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var L=(n,t)=>{for(var o in t)P(n,o,{get:t[o],enumerable:!0})},u=(n,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of E(t))!f.call(n,e)&&e!==o&&P(n,e,{get:()=>t[e],enumerable:!(a=D(t,e))||a.enumerable});return n};var S=(n,t,o)=>(o=n!=null?g(N(n)):{},u(t||!n||!n.__esModule?P(o,"default",{value:n,enumerable:!0}):o,n)),w=n=>u(P({},"__esModule",{value:!0}),n);var M={};L(M,{createGetInitialProps:()=>C});module.exports=w(M);var l=S(require("next/document"));var y="_initialState",I="__NEXT_INITIAL_STATE";var p=require("react/jsx-runtime"),C=n=>async t=>{let o={props:void 0},a=t.renderPage;t.renderPage=({enhanceApp:r,enhanceComponent:d})=>a({enhanceApp:i=>s=>{o.props=s;let c=(r==null?void 0:r(i))||i;return(0,p.jsx)(c,{...s})},enhanceComponent:d});try{await l.default.getInitialProps(t)}catch{}let e=await n(o.props,t),_={[y]:e};t.renderPage=({enhanceApp:r,enhanceComponent:d})=>a({enhanceApp:i=>s=>{let c=(r==null?void 0:r(i))||i;return(0,p.jsx)(c,{...s,..._})},enhanceComponent:d});let m=await l.default.getInitialProps(t);return{...m,head:[...m.head||[],(0,p.jsx)("script",{dangerouslySetInnerHTML:{__html:`window.${I}=${JSON.stringify(e)};`}})]}};0&&(module.exports={createGetInitialProps});
"use strict";var g=Object.create;var P=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var e in t)P(n,e,{get:t[e],enumerable:!0})},y=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of N(t))!L.call(n,o)&&o!==e&&P(n,o,{get:()=>t[o],enumerable:!(a=E(t,o))||a.enumerable});return n};var f=(n,t,e)=>(e=n!=null?g(D(n)):{},y(t||!n||!n.__esModule?P(e,"default",{value:n,enumerable:!0}):e,n)),w=n=>y(P({},"__esModule",{value:!0}),n);var M={};S(M,{createGetInitialProps:()=>C});module.exports=w(M);var c=f(require("next/document"));var u="_initialState",I="__NEXT_INITIAL_STATE";var d=require("react/jsx-runtime"),C=n=>async t=>{let e=t.renderPage,a;t.renderPage=({enhanceApp:r,enhanceComponent:l})=>e({enhanceApp:i=>s=>{a=s;let p=(r==null?void 0:r(i))||i;return(0,d.jsx)(p,{...s})},enhanceComponent:l});try{await c.default.getInitialProps(t)}catch{}let o=await n(a,t),_={[u]:o};t.renderPage=({enhanceApp:r,enhanceComponent:l})=>e({enhanceApp:i=>s=>{let p=(r==null?void 0:r(i))||i;return(0,d.jsx)(p,{...s,..._})},enhanceComponent:l});let m=await c.default.getInitialProps(t);return{...m,head:[...m.head||[],(0,d.jsx)("script",{dangerouslySetInnerHTML:{__html:`window.${I}=${JSON.stringify(o)};`}})]}};0&&(module.exports={createGetInitialProps});
//# sourceMappingURL=createGetInitialProps.js.map

@@ -1,7 +0,4 @@

import * as redux from 'redux';
import { EnhancedStore, PreloadedState } from '@reduxjs/toolkit';
declare type MakeStore = (preloadedState?: any | undefined) => any;
declare const createUseStore: (makeStore: MakeStore) => (appProps: any) => any;
declare type MakeStore = (preloadedState?: PreloadedState<any>) => EnhancedStore;
declare const createUseStore: (makeStore: MakeStore) => (appProps: any) => EnhancedStore<any, redux.AnyAction, readonly redux.Middleware<{}, any, redux.Dispatch<redux.AnyAction>>[]>;
export { createUseStore };

@@ -1,2 +0,2 @@

"use strict";var a=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},c=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of s(e))!A.call(t,r)&&r!==o&&a(t,r,{get:()=>e[r],enumerable:!(n=_(e,r))||n.enumerable});return t};var i=t=>c(a({},"__esModule",{value:!0}),t);var m={};E(m,{createUseStore:()=>l});module.exports=i(m);var p=require("react");var S="_initialState",d="__NEXT_INITIAL_STATE";var l=t=>e=>(0,p.useMemo)(()=>{let o=e[S]||globalThis[d];return t(o)},[]);0&&(module.exports={createUseStore});
"use strict";var r=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var o in e)r(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of i(e))!M.call(t,a)&&a!==o&&r(t,a,{get:()=>e[a],enumerable:!(n=A(e,a))||n.enumerable});return t};var E=t=>d(r({},"__esModule",{value:!0}),t);var c={};S(c,{createUseStore:()=>N});module.exports=E(c);var s=require("react");var _="_initialState",p="__NEXT_INITIAL_STATE";var N=t=>e=>(0,s.useMemo)(()=>{let o=e[_]||globalThis[p];return t(o)},[]);0&&(module.exports={createUseStore});
//# sourceMappingURL=index.js.map
{
"name": "next-redux-store",
"version": "0.0.14",
"description": "",
"version": "0.1.0",
"description": "Next integration with Redux",
"keywords": [
"next",
"redux",
"store"
],
"main": "dist/index.js",

@@ -13,27 +18,10 @@ "module": "dist/index.mjs",

"scripts": {
"lint": "eslint src",
"watch": "tsup --clean --watch",
"build": "tsup --clean",
"prepublishOnly": "yarn run lint && yarn run build"
"lib:lint": "eslint src",
"lib:watch": "tsup --watch",
"lib:build": "tsup --clean",
"prepublishOnly": "yarn run lib:lint && yarn run lib:build"
},
"author": "Roman Samoylov (https://github.com/fakundo)",
"license": "ISC",
"devDependencies": {
"@reduxjs/toolkit": "^1.8.5",
"@types/react": "^18.0.21",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.24.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"next": "^12.3.1",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tsup": "^6.2.3",
"typescript": "^4.8.4"
},
"license": "MIT",
"peerDependencies": {
"@reduxjs/toolkit": "*",
"next": ">=10.0.0",

@@ -40,0 +28,0 @@ "react": ">=17.0.0"

@@ -1,1 +0,95 @@

WIP;
# next-redux-store
[![npm](https://img.shields.io/npm/v/next-redux-store.svg)](https://www.npmjs.com/package/next-redux-store)
Next integration with Redux.
Features:
- state data is passed to the client once when rendering the first page
- does not load state between page transitions
- does not use the HYDRATE action, instead uses preloadedState to configure store on the client once
- SSG and SSR work great
## Installation
```
npm i next-redux-store
```
## Demo
[Demo with RTK Query](https://fakundo.github.io/next-redux-store/)
/
[Source](https://github.com/fakundo/next-redux-store/tree/master/packages/docs)
## Usage
1. Configure your App to use Redux store
```js
import { makeStore, Provider } from 'modules/redux';
import { createUseStore } from 'next-redux-store';
import { AppProps } from 'next/app';
const useStore = createUseStore(makeStore);
export default function _App({ Component, pageProps, ...rest }: AppProps<any>) {
const store = useStore(rest);
return (
<Provider store={store}>
<Component {...pageProps} />
</Provider>
);
}
```
2. Configure your Document to provide initial state for the App
```js
import { makeStore } from 'modules/redux';
import { createGetInitialProps } from 'next-redux-store/createGetInitialProps';
const getInitialState = async (appProps, ctx) => {
if (!appProps) {
return undefined;
}
const store = makeStore();
// fill the store considering the App props and Document context
return store.getState();
}
export default class _Document extends Document {
static getInitialProps = createGetInitialProps(getInitialState);
render() {
...
}
}
```
## API
### createUseStore
createUseStore creates a React hook that returns a Redux store.
It accepts a store creation function with a preloadedState as parameter. The hook accepts App props.
```ts
type MakeStore = (preloadedState?: any | undefined) => Store;
const createUseStore: (makeStore: MakeStore) => (appProps: AppProps<any>) => Store;
```
### createGetInitialProps
createGetInitialProps creates a function that returns initial props for the Document, providing initialState of store for the App.
```ts
type CreateInitialState = (appProps?: AppProps<any> | undefined, ctx?: DocumentContext) => any;
const createGetInitialProps: (createInitialState: CreateInitialState) => (ctx: DocumentContext) => DocumentInitialProps;
```
createInitialState can accept two parameters: App props and Document context.
## License
MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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