Web development
The directive that crosses the boundary
About 2 min if you have seen this material before, 10 min or so if it is new to you.
Background
Since server rendering is the default, there has to be a way to say "this part is different". That way is a directive: a bare string literal on the first line of a file, a pattern JavaScript has used before for
"use strict".
There are two such directives here, and they point in opposite directions, which is why they are so easy to confuse. One marks code that must be sent to the browser. The other marks a function that stays on the server but may be *called* from the browser. That is a A function marked 'use server' that the browser can call directly, but which executes on the server., and it is how submitAnswer grades your answer without exposing the expected answer.
A directive marks a boundary, not merely a file: anything imported by a client component is pulled into the browser bundle too. Keeping that boundary small is why answer-form.tsx contains as little as it does.Which directive, written at the top of a file, opts that file's code into being sent to and run in the browser? Give the directive exactly as written.
Past 30 min on this? That usually means a missing prerequisite rather than a lack of effort — worth reading up before pushing further, starting with 'use client' (React docs).
Want to go deeper?