Oftentimes I’ll find myself writing some code similar to the following:
loadPuzzle: (state: AppState, action: PayloadAction<string>) => {
const newPuzzle = GetPuzzleByID(state, action.payload);
if (newPuzzle == null)
return console.error(
"Tried to load a puzzle that doesn't exist on this machine."
);
LoadPuzzle(state, newPuzzle);
}
i.e. I end up with a function someStatefulChange
that gets exported as a reducer for the slice, and an internal function SomeStatefulChange
that I can re-use elsewhere imported from another file.
Is this reasonable to do? Are there any potential downsides of this? Does anybody have a better way of approaching this? Is this a codesmell? I have no idea.