Next.js · Junior · Question 72 of 75
How does a server component read a request header like user-agent?
import { headers } from 'next/headers'
const ua = (await headers()).get('user-agent')- ✓Correct answer: Await
headers()fromnext/headersand call.get() - 2Read
window.navigator.userAgent - 3Headers are only available in Route Handlers
Explanation
headers() is async in Next.js 16 and returns read-only headers. Using it makes the route render at request time.