I'm using RematchJS and I'd like to access the state in a model effect without sending a payload to the effect.
The model looks something like this:
export const session = createModel<RootModel>()({
state: {
...
} as SessionModel,
reducers: {
setAuthenticated(state, payload) {
return {
...state,
isAuthenticated: payload,
};
}
},
effects: (dispatch) => ({
async logout(payload, rootState) {
const sessionId = rootState.session.sessionId;
if (sessionId) {
await ApiClient.logout(sessionId);
dispatch.session.setAuthenticated(false);
}
}
}),
});
The problem is that since the payload comes first in an effect, I must send some payload when I dispatch the effect otherwise typescript will complain:
dispatch.session.logout(somePayload);
I work around that by calling dispatch.session.logout(null);
but it feels incorrect.
Is there a nicer solution?