-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Useless (?) type property in createSlice #2623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a topic we specifically discussed in the early alpha design phase: We always pass the entire If you only care about
|
Can't you have them as the third and fourth argument? |
No. For one thing, it doesn't make any sense conceptually to take a single Like I said, if all you care about is |
When you create a slice, the reducers field is automatically split into all the action types so I don't see a reason to later include that property inside a function. Code could be a lot simpler if you could just have the second argument be the payload, not an object with both the action and the payload:
instead of
If, in that rare case, you need the type in the action, why not just pass it as the third argument?
Redux Toolkit states on its website that it's simple, however it could be simpler (as in the first code block). To make this work in my project, I have this wrapper:
So users have a choice - write something weird like this or repetitively write
PayloadAction
in their reducers and take out thepayload
field from the object. Does it have to be like that? If you don't want to change this in Redux Toolkit because the fieldreducers
would not fit the definition of a reducer anymore (that accepts state as one argument and the action as the second), you could call thisactionHandlers
or justhandlers
or something and have it be an opt-in alternative forreducers
(just another optional field while keeping the old one).The text was updated successfully, but these errors were encountered: