The useEffect
hook in React is a way to use lifecycle methods in functional components. It runs after every render by default, but can also be set to run only when certain props or state values change.
Here is an example of how to use useEffect
to fetch data from an API:
459 chars23 lines
In this example, useEffect
is called with a function that fetches data from an API when the component mounts (or when []
changes). The fetched data is stored in data
using the useState
hook. The component renders the fetched data in a list.
gistlibby LogSnag