3 ms·
Surprised at the negative comments already. I'm not sure half of the commenters use React on a daily basis. I've re-written these same hooks in various ways, as
by mattwad 5y ago
Surprised at the negative comments already. I'm not sure half of the commenters use React on a daily basis. I've re-written these same hooks in various ways, as well as used ones written by others. This look great to me, personally! I've been using a weird implementation of useReducer() (most commonly suggested on SO) but extendState() is a more elegant solution.
Couple suggestions:
* the repetition of "read" `const [ readRequest, requestRead ] = usePromise(read)` makes it hard for me to keep these things separate. It would be easier if you had a real life example, like "get users" or something but even somethin like `const [ apiState, fetchApiState ] = usePromise( apiRequest )` would be better IMO.
* `readRequest.cancel` - sometimes I've wanted to cancel a request but it's not an error to show the user, but it looks like the view wouldn't be able to tell the difference from a regular http error
* `readRequest.reset(`error`)` could be another way to just reset a single property, instead of having to use brackets
* uh where is the code for the hooks? A direct link to code or even a library would be great
- loh 5y agoThat's a good call. I'll change those to better names. Also, you can call `cancel()` (with no arguments) if you don't want an error. You can find the code for the hooks here: https://github.com/Molecule-dev/molecule-app/tree/_e745872f9c566d0b7c6bdfce748f2ab4b809c0ca/src/hooks https://github.com/Molecule-dev/molecule-app/tree/_e745872f9... I'll add a direct link to that too. I really appreciate the feedback.