Bird
Raised Fist0
Astroframework~20 mins

Markdown and MDX pages in Astro - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Astro MDX Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the rendered output of this Astro MDX component?

Given this Astro MDX page, what will be the visible output in the browser?

Astro
---
const name = 'Astro Learner';
---
# Welcome, {name}!

This is a simple MDX page.
A<h1>Welcome, Astro Learner!</h1><p>This is a simple Astro page.</p>
B<h1>Welcome!</h1><p>This is a simple MDX page.</p>
C<h1>Welcome, {name}!</h1><p>This is a simple MDX page.</p>
D<h1>Welcome, Astro Learner!</h1><p>This is a simple MDX page.</p>
Attempts:
2 left
💡 Hint

Remember Astro MDX supports JavaScript expressions inside curly braces.

📝 Syntax
intermediate
2:00remaining
Which MDX syntax correctly imports and uses a React component in Astro?

Choose the correct way to import and use a React component Button inside an Astro MDX page.

A
&gt;nottuB/&lt;em kcilC&gt;nottuB&lt;
---
;'xsj.nottuB/stnenopmoc/..' morf nottuB tropmi
---
B
---
import { Button } from '../components/Button.jsx';
---
&lt;Button&gt;Click me&lt;/Button&gt;
C
---
import Button from '../components/Button.jsx';
---
&lt;Button&gt;Click me&lt;/Button&gt;
D
---
import Button from '../components/Button.jsx';
---
&lt;button&gt;Click me&lt;/button&gt;
Attempts:
2 left
💡 Hint

Astro MDX supports default imports with semicolons and JSX usage.

🔧 Debug
advanced
2:00remaining
Why does this Astro MDX page fail to render?

Identify the cause of the rendering error in this Astro MDX page:

Astro
---
const title = 'Hello World'
---
# {title}

Some content here.
AMissing semicolon after variable declaration causes syntax error.
BCurly braces cannot be used inside Markdown headings in MDX.
CThe variable <code>title</code> is not defined in the frontmatter.
DMDX requires explicit export of variables to use them in content.
Attempts:
2 left
💡 Hint

Check JavaScript syntax in the frontmatter section.

❓ state_output
advanced
2:00remaining
What is the output of this Astro MDX page with a React counter component?

Consider this Astro MDX page that imports a React counter component. What will the initial rendered HTML show?

Astro
---
import Counter from '../components/Counter.jsx';
---
# Counter Demo

<Counter />
A<h1>Counter Demo</h1><button>Count: 0</button>
B<h1>Counter Demo</h1><button>Count: 1</button>
C<h1>Counter Demo</h1><button>Count: </button>
D<h1>Counter Demo</h1><button>Click me</button>
Attempts:
2 left
💡 Hint

React components start with initial state on first render.

🧠 Conceptual
expert
2:00remaining
How does Astro handle hydration for React components in MDX pages?

Which statement best describes how Astro hydrates React components used inside MDX pages?

AAstro always hydrates all React components on the client by default without any special directives.
BAstro renders React components to static HTML and hydrates them on the client only when specified with <code>client:load</code> or similar directives.
CAstro does not support React components inside MDX pages at all.
DAstro hydrates React components on the server and sends fully interactive HTML to the client.
Attempts:
2 left
💡 Hint

Think about Astro's partial hydration approach.

Practice

(1/5)
1. What is the main difference between Markdown and MDX in Astro?
easy
A. Markdown supports JavaScript code, but MDX does not.
B. Markdown files can run server code, MDX files cannot.
C. MDX is only for styling, Markdown is for content.
D. MDX allows embedding components inside Markdown content, while Markdown does not.

Solution

  1. Step 1: Understand Markdown basics

    Markdown is a simple way to write formatted text like headings, lists, and links.
  2. Step 2: Understand MDX extension

    MDX extends Markdown by allowing you to include interactive components inside the text.
  3. Final Answer:

    MDX allows embedding components inside Markdown content, while Markdown does not. -> Option D
  4. Quick Check:

    MDX = Markdown + components [OK]
Hint: Remember: MDX = Markdown + components [OK]
Common Mistakes:
  • Thinking Markdown supports components
  • Confusing MDX with styling only
  • Believing Markdown runs server code
2. Which file extension should you use for a page that includes React components inside Markdown in Astro?
easy
A. .mdx
B. .astro
C. .md
D. .jsx

Solution

  1. Step 1: Identify file types for Markdown and MDX

    Markdown files use .md extension, MDX files use .mdx extension to support components.
  2. Step 2: Match file extension to React components inside Markdown

    To include React components inside Markdown, use .mdx files.
  3. Final Answer:

    .mdx -> Option A
  4. Quick Check:

    React components in Markdown = .mdx [OK]
Hint: Use .mdx for Markdown with components [OK]
Common Mistakes:
  • Using .md for MDX content
  • Confusing .astro with Markdown files
  • Choosing .jsx which is for pure React files
3. Given this Astro MDX page snippet, what will be rendered?
---
import Button from '../components/Button.jsx';
---
# Welcome
Click me
medium
A. A syntax error because components can't be imported in MDX.
B. Only the heading 'Welcome' without the button.
C. A heading 'Welcome' and a clickable button labeled 'Click me'.
D. The button renders but the heading does not.

Solution

  1. Step 1: Understand MDX import and usage

    MDX allows importing components at the top and using them inline in the Markdown content.
  2. Step 2: Analyze the snippet output

    The heading '# Welcome' renders as a heading, and the <Button> component renders as a clickable button with text 'Click me'.
  3. Final Answer:

    A heading 'Welcome' and a clickable button labeled 'Click me'. -> Option C
  4. Quick Check:

    MDX imports + components = rendered output [OK]
Hint: MDX imports components, renders both text and UI [OK]
Common Mistakes:
  • Thinking imports cause syntax errors in MDX
  • Assuming components won't render inside MDX
  • Ignoring Markdown headings when components are present
4. What is wrong with this Astro MDX page snippet?
---
import Alert from '../components/Alert.jsx'
---
# Notice
This is important
medium
A. No error; this code is correct.
B. Incorrect import path syntax.
C. Missing semicolon after import statement.
D. Missing closing quote in import statement.

Solution

  1. Step 1: Check import syntax in MDX frontmatter

    In MDX frontmatter, semicolons are optional and import paths use quotes correctly.
  2. Step 2: Verify component usage

    The Alert component is imported and used correctly inside the MDX content.
  3. Final Answer:

    No error; this code is correct. -> Option A
  4. Quick Check:

    MDX import syntax is flexible = correct [OK]
Hint: Semicolons optional in MDX imports [OK]
Common Mistakes:
  • Expecting semicolons after imports
  • Thinking import paths need special syntax
  • Assuming missing semicolon causes error
5. You want to create a blog post in Astro that uses Markdown for text and includes a custom interactive component for comments. Which approach is best?
hard
A. Write the entire post in .md and import the component inside it.
B. Use .mdx for the post so you can embed the comment component directly.
C. Create a .astro page and write Markdown inside it manually.
D. Use .md and add the component via client-side JavaScript after page load.

Solution

  1. Step 1: Understand Markdown limitations

    Plain .md files cannot embed components directly; they are static content.
  2. Step 2: Consider MDX advantages

    .mdx files allow mixing Markdown with components, perfect for interactive elements like comments.
  3. Step 3: Evaluate other options

    .astro pages can include Markdown but require more setup; client-side JS injection is less clean and less integrated.
  4. Final Answer:

    Use .mdx for the post so you can embed the comment component directly. -> Option B
  5. Quick Check:

    Interactive + Markdown = MDX [OK]
Hint: Embed components directly by using .mdx files [OK]
Common Mistakes:
  • Trying to import components in plain .md files
  • Ignoring MDX for interactive content
  • Overcomplicating with client-side JS injection
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard