FAQ: Components and Advanced JSX - Components Recap

This community-built FAQ covers the “Components Recap” exercise from the lesson “Components and Advanced JSX”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn ReactJS: Part I

FAQs on the exercise Components Recap

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

So, with regards to Components and Advanced JSX, 6/6:

If you would like to practice your learned skills, consider these challenges:
Add logic to the MyQuote component to produce different quotes based on different conditions.
Add elements onto the screen that can respond to events such as clicking or hovering. Make sure to define event handlers for them within the component.

Any thoughts about the following? Hovering does not work, everything else does:

import React, { useState } from 'react'; //to use state & react functional event handler components

function MyQuote() { //definition of MyQuote component as a function with 3 state variables using hook = useState
  const [quote, setQuote] = useState("Initial quote");
  const [message, setMessage] = useState("");
  const [condition, setCondition] = useState(false);

//now 3 event handlers
  const handleClick = () => {
    setQuote("New quote after clicking the button!");
  };

  const handleMouseOver = () => {
    setMessage("You are hovering over the paragraph!");
  };

  const handleToggleCondition = () => {
    setCondition(!condition);
  };

  let displayedQuote = quote;

  if (condition) {
    displayedQuote = "Alternate quote";
  }

  return (
    <div>
      <blockquote>
        <p>{displayedQuote}</p>
        <cite>
          <a target="_blank" href="https://en.wikipedia.org/wiki/Susan_Sontag">
            Susan Sontag
          </a>
        </cite>
      </blockquote>
      <button onClick={handleClick}>Change Quote</button>
      <p onMouseOver={handleMouseOver}>{message}</p>
      <button onClick={handleToggleCondition}>Toggle Condition</button>
    </div>
  );
}

export default MyQuote;