0

I have this react app, and this component in specific, has a useReducer in order to save a lot of data that it handles.

The problem, is that i'm finding myself creating functions where i dispatch multiple actions, and i'm worried that this could cause performance-rendering problems like happens when you use redux.

When you use react-redux you have the ability to use batch() to only have 1 render when you have to dispatch multiple actions, but, when you use react useReducer hook, is there such thing like that ?

This is the code where i'm having this problem.

<Box
                onClick={() => {

                    dispatchMetaState({
                        type: 'GET_CENTER_LOCATION',
                        payload: center,
                    });

                    dispatchMetaState({
                        type: 'ADJUST_ZOOM',
                        payload: zoom,
                    });

                    if(isResourceLocated !== '') dispatchMetaState({type:'UNLOCATE_RESOURCE'})

                }}
>

</Box>

Any thoughts, ideas ?

Diego
  • 421
  • 3
  • 9
  • 34
  • 1
    Starting React 18, React automatically batches the updates. I am pretty confident it does it for multiple `setState` for `useState` inside a component. – user18821127 Jul 15 '22 at 01:19
  • And also for dispatch from useReducer ? Yeah i think so, because, if i'm not wrong, useState under the hood uses useReducer or something like that. And, we haven't moved yet to react 18 ); – Diego Jul 15 '22 at 13:02

0 Answers0