But it shows "Hello, undefined!" What is the likely problem?
medium
A. Astro does not support variables in templates.
B. SSR is disabled by default, so dynamic code does not run.
C. fetchUserName() is asynchronous but used without await.
D. The variable userName must be declared inside the template.
Solution
Step 1: Identify async function usage
fetchUserName() likely returns a Promise, so it must be awaited to get the value.
Step 2: Understand why undefined appears
Without await, userName is a Promise object, which renders as undefined in template.
Final Answer:
fetchUserName() is asynchronous but used without await. -> Option C
Quick Check:
Async functions need await to get values [OK]
Hint: Await async calls to get real values in SSR [OK]
Common Mistakes:
Forgetting to await async functions
Assuming SSR is off by default
Thinking variables must be inside template tags
5. You want to show a personalized greeting on your Astro page that updates every time a user visits, using SSR. Which approach correctly achieves this?