이미 알지만 중요한 문장:
APIs are an intermediary layer between your application code and database. There are a few cases where you might use an API:
Client Component의 경우, 컴포넌트 내에서 Promises나 async/await을 사용할 수 있다.
'use client';
import { useState } from 'react';
function Search() {
const [results, setResults] = useState([]);
// ✅ async function INSIDE the component — totally fine
async function handleSearch() {
const res = await fetch('/api/search');
setResults(await res.json());
}
return <button onClick={handleSearch}>Search</button>;
}