Why does the component dispatching an action for updating react-redux state re-renders after store state changes? Shouldn't the re-render occur only when props or component state changes?
const BoxContainer=memo(({props})=>{
const dispatch = useDispatch();
//Setting action with dispatch with useCallBack hook for safe side
const callAction =useCallback(
(payload) => {
dispatch(payload)
},
[],
);
const structure = useSelector(state => ({...state.FormState}));
var form = generateForm(structure,callAction);
return(
<React.Fragment>
{form}
</React.Fragment>
);
});
Reducer code is given below
export const FormState = (state = FormStructureState ,action) =>
{
switch(action.type){
case 'UPDATE':
return {
...state,
Structure:action.Payload
}
case 'MOVEITEM':
var sourceRow = action.sourceRow;
var sourceCol = action.sourceCol;
var destRow = action.destRow;
var destCol = action.destCol;
var destinationContent = state.Structure.row[destRow][destCol].content;
state.Structure.row[destRow][destCol].content = state.Structure.row[sourceRow][sourceCol].content;
state.Structure.row[sourceRow][sourceCol].content = destinationContent;
return {...state}
case 'SETTEMPLATE':
var sourceRow = action.sourceRow;
var sourceCol = action.sourceCol;
state.Structure.row[sourceRow][sourceCol].content.template = action.template;
default:
return {...state}
}
}