Complete the code to import the Next.js geolocation hook.
import { [1] } from 'next/navigation';
The useGeolocation hook is used to access geolocation data in Next.js edge components.
Complete the code to get the user's current position inside a React component.
const position = [1]();The useGeolocation hook returns the user's current position in Next.js edge components.
Fix the error in the edge function export to enable geolocation support.
export const runtime = [1];Setting runtime to 'edge' enables edge functions which support geolocation in Next.js.
Fill both blanks to create a server action that uses geolocation and returns the country code.
export const getCountry = async () => {
const { country } = await fetch('/api/geo').then(res => res.json());
return country [1] 'US' ? 'USA' : 'Other';
};
export const runtime = [2];The code compares the country code with 'US' using strict equality ===. The runtime must be set to 'edge' to support geolocation.
Fill all three blanks to create a Next.js server component that fetches geolocation and displays the city.
import React from 'react'; export const runtime = [1]; export default async function GeoCity() { const res = await fetch('/api/geo'); const data = await res.json(); const city = data.[2] ?? 'Unknown'; return <p>Your city is: [3]</p>; }
The runtime is set to 'edge' for geolocation support. The city is accessed from the data object by the key city. The JSX expression uses curly braces {city} to display the city value.