Can react hooks completely replace redux?
Answer a question
I am learning react hooks, and so far, I´ve seen that are a way to make react 'reactive' which it was not before this cool new thing.
I've also tried to share the state between different components using hooks, and when a component change any value inside the state, the other components get the updates. So that made me think, can Redux or any other state management solution be completely replaced by react hooks? Is there any pros and cons?
Anything I should consider before trying to migrate my redux based app to hooks? I am not a fan of big 3rd party libraries and if I can achieve the same goals with the tools that react can offer, why not?
Answers
If your use of redux is only based on the need to avoid prop-drilling, then react context ( using hooks or not ) could be enough for you.
But to answer your question: no. You can totally implement your version of dispatch action and get state with context and hooks alone, without redux, but redux offer more to the table than them. Middleware, ability to persist the state of your app, easier debug, etc.
If your app doesn't require all the benefits that redux could provide, then don't use it. But the statement "can context + hooks replace redux?" is false.
更多推荐
所有评论(0)