5 ms·
Yes you are correct that we can use useSelector to optimize selectors for Redux and I even implemented this hook in an interview on the whiteboard :D. And yeah
by vijaybritto 6y ago
Yes you are correct that we can use useSelector to optimize selectors for Redux and I even implemented this hook in an interview on the whiteboard :D.
And yeah components are supposed to select only what they need in mapStateToProps and mapDispatchToProps. But I have seen a couple of instances where this is not followed and the developer chooses to use the entire state object passed to the component. This was fixed quickly and all developers got a short doc on the do's and dont's of Redux. This is what I mean by the extra work around redux library and not the concept itself.
Also its a fairly common to see developers pushing multiple micro updates like keystrokes to redux making it slow down. This gets filtered in the reviews but it misses out sometimes. I'm guessing this to happen in many other projects too unless I'm missing out on some major update on the tooling around redux.
These problems are not because of the approach but in the implementations. I hope you get what I mean by cost in my opinion above.
- tga 6y agoAgreed then, Redux does give you enough rope to get into trouble, especially when used indiscriminately.
- mosdl 6y agoYou still have to run the selectors for all components on each change and check if their result has changed and if so, update the component props. So the more components, the more memory/cpu you waste on each redux update. So now you have to use something like reselect to start caching results...