Hi, I'm a Redux maintainer. Unfortunately, I have concerns with several of the things you've shown here in this post - the code patterns shown are the opposite of how we recommend people use Redux today.
You should be using our official Redux Toolkit package and following our guidelines for using Redux with TypeScript correctly. That will eliminate all of the hand-written action types, action creators, and a lot of the other code you've shown, as well as simplifying the store setup process. You're also splitting the code across multiple files by type, and we recommend keeping logic in a single-file "slice" per feature.
For example, this is what that "app slice" would look like with RTK + TS:
Notice how few TS typedefs are needed. We just need one for the initial state, and one for the payload of this action, and that's it. Everything else is inferred.
Thanks for your feedback, yeah, for sure to simplify code we should use redux-toolkit, but my idea was to show how we can manually set up with typescript our redux structure, just as an example how to have custom control at redux, probably or most likely its over-coding, I guess that for complex logic it has the right to exist due to a lot of error handlers, I am so sorry if somebody was misled due to title of the story. So should I delete the story or change totally sm?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, I'm a Redux maintainer. Unfortunately, I have concerns with several of the things you've shown here in this post - the code patterns shown are the opposite of how we recommend people use Redux today.
You should be using our official Redux Toolkit package and following our guidelines for using Redux with TypeScript correctly. That will eliminate all of the hand-written action types, action creators, and a lot of the other code you've shown, as well as simplifying the store setup process. You're also splitting the code across multiple files by type, and we recommend keeping logic in a single-file "slice" per feature.
For example, this is what that "app slice" would look like with RTK + TS:
Notice how few TS typedefs are needed. We just need one for the initial state, and one for the payload of this action, and that's it. Everything else is inferred.
Note that we also recommend using pre-typed React-Redux hooks as well.
Please switch to using the patterns we show in the docs - it'll make everything much simpler!
Thanks for your feedback, yeah, for sure to simplify code we should use redux-toolkit, but my idea was to show how we can manually set up with typescript our redux structure, just as an example how to have custom control at redux, probably or most likely its over-coding, I guess that for complex logic it has the right to exist due to a lot of error handlers, I am so sorry if somebody was misled due to title of the story. So should I delete the story or change totally sm?