-
Hi I have a slice that looks like this. export const slice = createSlice({
name: 'slice',
initialState,
reducer: {
... // bunch of actions in here
}
}) I have a bunch of actions inside that reducer object. And I would like to extract them all to a separate file, maybe called slice.actions.js Just to make the code a bit cleaner and readable. I've looked at a bunch of resources, and haven't found what I'm looking for. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Honestly, if you take all actions out of that file and put them into one new file, your new file will be 10 lines shorter. Generally, these reducers are just functions. You can declare them wherever you want, import them and just put them into the Personally I'd rather extract some common code into functions that you call from those case reducers. |
Beta Was this translation helpful? Give feedback.
Honestly, if you take all actions out of that file and put them into one new file, your new file will be 10 lines shorter.
Generally, these reducers are just functions. You can declare them wherever you want, import them and just put them into the
reducers
object here. But at that point you will have to annotate them with types manually if you are using TypeScript.Personally I'd rather extract some common code into functions that you call from those case reducers.