Grokking React Fundamentals
Vote

0% completed

​

Building a Data Fetching Hook

A custom hook can return anything: a single value, a function, an array, or an object. The useWindowWidth hook from the previous lesson returns a single value, the current width of the window. It is a function whose name starts with use and which calls useState and useEffect, and every component that calls it gets its own state and its own effect.

Data fetching is a good case for returning an object, because a component needs three things from it: the data, whether it is still loading, and an error message if the request failed.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content