|

React Hook useContextAndReducer

I’ve been tinkering with React quite a lot as of recently & I’ve been working on some very complex systems, one’s where there are so many variables associated with state that one minor modification has an immensely dramatic impact on the overall application state.

I mean this application has got to the point where it’s so complex that I’ve even adopted nested reducers, i.e. on the action that’s passed into the dispatch function, it has both a type & a parent type to distinguish which reducer needs to be used for a given action at a given point.

But one thing that I’ve been trying to achieve is to essentially merge the state that’s handled within these reducers with a given context so that the state can be shared across a vast number of components. Queue the birth of the useContextAndReducer hook. I decided that it would be appropriate to create a hook for this specifically because I found that there are several places throughout the application that needed to merge local state with the global state in a seamless & simplistic fashion.

Obviously I had to go with a to-do application, would I even be a competent React developer if I didn’t do either a to-do application or some counter application? I think not! Anyway I hope that you quite like this approach, if you have any better ideas, I’d love to hear from you! 🙂

Similar Posts

  • | | |

    Node Containers

    I feel somewhat ashamed of myself that I’m only now learning about this problem(s) with process shut down with Node & Docker. After finding Bret Fisher’s talk(s) about Node & Docker best practices, I couldn’t believe that there’s a bit of an issue with process signal making it all the way through to the application….

  • |

    React Hooks

    I’d like to keep this post short as I’ve just bought my first house with my girlfriend (I may write a short post about it later), so there’s still boxes everywhere & on top of that I’m still working full time from home, so I’m pretty darn busy to say the very least. Anyway, I…

  • |

    React Rocks

    As some of you may or may not know, I freaking love React, in contrast to the likes of Angular or Vue, I just personally find that it’s a lot less opinionated. An example being how you get the argument that React isn’t a framework, sure it isn’t, but that’s one thing that makes it…

Leave a Reply

Your email address will not be published. Required fields are marked *