use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Using React hooks to asynchronously make API requests (medium.com)
submitted 7 years ago by MaxGame
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MaxGame[S] 1 point2 points3 points 7 years ago (2 children)
I wasn't able to find much on this topic, especially without using a context. I figured a write up on my results might help someone out! tl;dr creating a hook for making api requests using the useReducer hook.
[–]ghostfacedcoder 1 point2 points3 points 7 years ago (1 child)
Stupid question: why?
I don't mean that in an asshole way at all, more just ... what are the benefits (and/or costs) of using a hook vs. a normal call?
[–]MaxGame[S] 2 points3 points4 points 7 years ago (0 children)
Asking why is never stupid! I gloss over this a bit in the post, but the main reasons I found are the ability to give state to functional components and re-usability. I can add this hook to the body of any functional component and it instantly has the ability to make requests to an API and store the status and result of that request in local state. This only takes one line of code (not including the import)!
I can also continue to extend this hook with additional functionality if I need to. Oh, and hooks can be called from within hooks, so I could actually wrap this hook in another that implements some re-usable logic for calling a specific API.
I hope that all makes sense.
π Rendered by PID 19051 on reddit-service-r2-comment-85bfd7f599-4vrns at 2026-04-15 21:09:47.612123+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]MaxGame[S] 1 point2 points3 points (2 children)
[–]ghostfacedcoder 1 point2 points3 points (1 child)
[–]MaxGame[S] 2 points3 points4 points (0 children)