I am working on a Next.js application with App Router and noticed that my API route is getting called twice during development.
I have a simple fetch inside useEffect:
useEffect(() => {
fetchUsers()
}, [])
Inside fetchUsers() I call my API route:
const fetchUsers = async () => {
const res = await fetch('/api/users')
const data = await res.json()
console.log(data)
}
The issue is that the API route logs twice in the terminal even though the component renders once visually.
I checked:
dependency array is empty
no duplicate components
API route works correctly in production build
Is this related to React Strict Mode in Next.js development mode, or am I missing something else?
Using:
Next.js 14
React 18
App Router