From debf83a5040680bfa219a04451b854b90b4da4f6 Mon Sep 17 00:00:00 2001 From: Kevin Mario Gerard <30295168+KevinMarioGerard@users.noreply.github.com> Date: Fri, 31 Jan 2020 01:33:04 +0530 Subject: [PATCH] Memoizing composed reducer (#79) --- src/components/Shuttle/hooks/useShuttleState.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Shuttle/hooks/useShuttleState.ts b/src/components/Shuttle/hooks/useShuttleState.ts index ceb3f47..c9d9eda 100644 --- a/src/components/Shuttle/hooks/useShuttleState.ts +++ b/src/components/Shuttle/hooks/useShuttleState.ts @@ -84,10 +84,15 @@ export function useShuttleState( }, reducers: { [key: string]: Function } = {} ) { + const composedReducer = React.useCallback( + composeReducers({ move, moveAll, selectItem, lazyLoad, ...reducers }), + [] + ); + // TODO: fix the type errors // @ts-ignore const [shuttleState, setShuttleState] = React.useReducer( - composeReducers({ move, moveAll, selectItem, lazyLoad, ...reducers }), + composedReducer, { ...initialState, // @ts-ignore