ReasonReact + useReducer hooks
This Gist is based on a tweet & blog post by Prateek Pandey on how to use a record based reducerComponent with ReasonReact : https://blog.theporter.in/reason-react-component-29fbffd784d6
It's based on the old record API, so I wanted to make an example which uses the newest ReasonReact API which is based on React hooks. IMO the hooks based API is much more lightweight and easier to understand. You can find more infos about it in the official ReasonReact docs.
Below you will find a similar solution to the Loadable state tracking as described in the blog post.
The first example shows state tracking via a reducer (
useReducer), the second example shows a more simplistic version with
useState (the one I would prefer for this specific use-case).
To conclude, the latest ReasonReact update is amazing. If you haven't had the time to look into it, I strongly encourage to check it out :-)