Next.js beginner 15 min

API Calls

Learn about API Calls in Next.js.

API Calls

In React, you can fetch data from an API using the browser fetch() function or libraries like axios. You usually call the API inside useEffect.

Example

useEffect(() => {
  fetch('/api/users')
    .then(res => res.json())
    .then(data => setUsers(data));
}, []);

Practice

Fetch a list of users from JSONPlaceholder and display their names.