Complete the code to create a Remix loader function that fetches data.
export async function loader() {
const data = await fetch('/api/data').then(res => res.[1]());
return data;
}The json() method parses the response as JSON, which is common in Remix loaders.
Complete the Next.js code to fetch data inside getServerSideProps.
export async function getServerSideProps() {
const res = await fetch('https://api.example.com/data');
const data = await res.[1]();
return { props: { data } };
}Next.js uses json() to parse API responses as JSON inside getServerSideProps.
Fix the error in this Remix route component to use the correct hook for data loading.
import { [1] } from '@remix-run/react'; export default function Dashboard() { const data = [1](); return <div>{JSON.stringify(data)}</div>; }
useLoaderData is the Remix hook to access data returned from the loader function.
Fill the blank to define a Next.js API route handler that returns JSON data.
export default function handler(req, res) {
res.[1]({ message: 'Hello from API' });
}Use res.json() to send JSON data in Next.js API routes.
Fill all three blanks to create a Remix form that submits data and handles the action.
import { Form, useActionData } from '@remix-run/react'; export async function action({ request }) { const formData = await request.[1](); const name = formData.get('[2]'); return { message: `Hello, ${name}` }; } export default function Greeting() { const data = useActionData(); return ( <Form method="post"> <input type="text" name="[3]" aria-label="Name" /> <button type="submit">Greet</button> {data && <p>{data.message}</p>} </Form> ); }
Use request.formData() to get form data, then formData.get('name') to access the input value named 'name'.