0
0
Reactframework~20 mins

Navigation links in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this React navigation component?
Consider this React component that renders navigation links. What will be displayed in the browser?
React
import React from 'react';
import { Link } from 'react-router-dom';

export default function Nav() {
  return (
    <nav aria-label="Main navigation">
      <ul>
        <li><Link to="/home">Home</Link></li>
        <li><Link to="/about">About</Link></li>
        <li><Link to="/contact">Contact</Link></li>
      </ul>
    </nav>
  );
}
AA navigation bar with three clickable links labeled Home, About, and Contact.
BA navigation bar with three links but only Home and About are clickable; Contact is plain text.
CAn error because Link components require an href attribute instead of to.
DNothing renders because the component is missing a return statement.
Attempts:
2 left
💡 Hint
Remember that React Router's Link uses 'to' for navigation paths.
state_output
intermediate
2:00remaining
What is the active link after clicking?
This React component highlights the active navigation link. After clicking the About link, what is the value of the active state?
React
import React, { useState } from 'react';

export default function Nav() {
  const [active, setActive] = useState('Home');

  return (
    <nav aria-label="Main navigation">
      <ul>
        <li>
          <button onClick={() => setActive('Home')} aria-current={active === 'Home' ? 'page' : undefined}>Home</button>
        </li>
        <li>
          <button onClick={() => setActive('About')} aria-current={active === 'About' ? 'page' : undefined}>About</button>
        </li>
        <li>
          <button onClick={() => setActive('Contact')} aria-current={active === 'Contact' ? 'page' : undefined}>Contact</button>
        </li>
      </ul>
    </nav>
  );
}
A"Contact"
B"Home"
C"About"
Dundefined
Attempts:
2 left
💡 Hint
Clicking the About button triggers setActive with 'About'.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in this React navigation code?
Identify which code snippet will cause a syntax error when used in a React component rendering navigation links.
React
function Nav() {
  return (
    <nav>
      <ul>
        <li><a href="/home">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/contact">Contact</a></li>
      </ul>
    </nav>
  );
}
Areturn <nav><ul><li><a href="/home">Home</a></li><li><a href="/about">About</a></li><li><a href="/contact">Contact</a></li></ul></nav>;
Breturn (<nav><ul><li><a href="/home">Home</a><li><a href="/about">About</a></li><li><a href="/contact">Contact</a></li></ul></nav>);
C;)>van/<>lu/<>il/<>a/<tcatnoC>"tcatnoc/"=ferh a<>il<>il/<>a/<tuobA>"tuoba/"=ferh a<>il<>il/<>a/<emoH>"emoh/"=ferh a<>il<>lu<>van<( nruter
Dreturn (<nav><ul><li><a href="/home">Home</a></li><li><a href="/about">About</a></li><li><a href="/contact">Contact</a></li></ul></nav>);
Attempts:
2 left
💡 Hint
Check if all tags are properly closed.