Question from the React ⚛️ test

Change the style of a button using the `useState` hook in React.

Easy

What is the outcome of executing the following React code (using the useState hook) to modify the style of a button?

import React, { useState } from 'react';

function App() {
  const [isHighlighted, setIsHighlighted] = useState(false);

  const buttonStyle = isHighlighted ? { backgroundColor: 'yellow' } : {};

  return (
    <button
      style={buttonStyle}
      onMouseEnter={() => setIsHighlighted(true)}
      onMouseLeave={() => setIsHighlighted(false)}
    >
      Hover over me
    </button>
  );
}
Author: Vincent CotroStatus: PublishedQuestion passed 1107 times
Edit
5
Community EvaluationsNo one has reviewed this question yet, be the first!