From 3fbf246fdbde61c413574f2792b991bfbd91f64e Mon Sep 17 00:00:00 2001 From: Sebastian Grebe Date: Tue, 22 Aug 2023 22:41:28 +0200 Subject: [PATCH] Add react-redux batch --- packages/wrapper/src/index.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/wrapper/src/index.tsx b/packages/wrapper/src/index.tsx index 2667f3f..c6d4cdb 100644 --- a/packages/wrapper/src/index.tsx +++ b/packages/wrapper/src/index.tsx @@ -9,7 +9,7 @@ import { NextComponentType, NextPageContext, } from 'next'; -import {useDispatch} from 'react-redux'; +import {useDispatch,batch} from 'react-redux'; /** * Quick note on Next.js return types: @@ -186,14 +186,16 @@ const getStates = ({ }; const dispatchStates = (dispatch: Dispatch, states: PageProps, config: Config) => - getStates(states).forEach((actions, source) => - getDeserialized(actions, config).forEach(action => - dispatch({ - ...action, - meta: {...(action as any).meta, source}, - }), - ), - ); + batch(() => { + getStates(states).forEach((actions, source) => + getDeserialized(actions, config).forEach(action => + dispatch({ + ...action, + meta: {...(action as any).meta, source}, + }), + ), + ) + }); export const createWrapper = (makeStore: MakeStore, config: Config = {}) => { const makeProps = async function

({