I'm using getServerSideProps with next-redux-wrapper. The issue is it invokes when I change the state on the button click.
as of my understanding, it should invoke only when we visit the page directly or navigate through the next link or route.
here is the code of getServerSideProps
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (context) => {
const session = await getSession(context);
const state = await store.getState();
if (!session) {
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
}
const permitedModels = session.permissions.map(
(permission) => permission.model.name
);
const permited = checkAccessibilty(state.investor.Models, permitedModels);
if (!permited) {
return {
redirect: {
destination: "/",
permanent: false,
},
};
}
store.dispatch(setFieldPermission([]));
}
);
here is my store configuration
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import investorSlice from "./investorSlice";
import permissionSlice from "./permissionSlice";
import { HYDRATE, createWrapper } from "next-redux-wrapper";
const combinedReducer = combineReducers({ investor: investorSlice, permission: permissionSlice });
const reducer = (state, action) => {
if (action.type === HYDRATE) {
const nextState = {
...state, // use previous state
...action.payload, // apply delta from hydration
};
debugger
return nextState;
} else {
return combinedReducer(state, action);
}
};
const makeStore = () => {
return configureStore({
reducer: reducer,
});
};
export const wrapper = createWrapper(makeStore);
On the button click I'm only updating the state. here is code
const clickHandler = () => {
if (!ctx.mode) {
ctx.setActiveMode("create");
} else {
ctx.setActiveMode("edit");
}
};
not able to find a reason behind the behavior.