-->

State management approach using react

2020-08-04 07:01发布

问题:

I have been using react for a while and at time I find it to be cumbersome to write action and reducers for simple tasks. The approach i use in such cases is as follows

I find this approach to be effective and less cumbersome in implementing. Any thoughts and drawbacks of this approach.

回答1:

React doesn't define how you should build your app and doesn't suggest a "default" architecture like some other frameworks (e. g. backbone) do. Also, redux is not a necessary part of react. It is used to prevent state from distributing across multiple components - but local state is not an antipattern and you indeed could/should have some. See this article from a redux co-author for details.

Regarding the architecture you you provided on the pic, well, this looks like classic MVC.

  • "Data provider component" = model
  • "Smart component" = controller
  • "Dumb component" = view

Again, react doesn't define what is wrong and what is right. Your idea looks fine. With proper implementation it could be very clear to comprehend.