...

/

Working with Data in Hooks

Working with Data in Hooks

Learn how to pass data in custom Hooks and return the response to the component that called the Hook.

Passing data via custom Hooks

Passing data via custom Hooks is not a one-way street. In our first custom Hook example, we’ve seen that we can pass data into a custom Hook as a function parameter. The Hook can also return data that can then be used in the component. The form in which this data is returned from the Hook is entirely at the developer’s discretion. You can easily return strings, tuples, and entire React components or elements, or even a combination of these.

Accessing data from an API

Let’s assume that we want to access data from an API. We should parameterize the data that we want to access to make it easier to work with. Hooks can help us access the data in this case (it does not matter in which component it ends up being used) and ...