Question from the React ⚛️ test

Write a React component that updates the document title with each click and resets to 'React App' when the component unmounts.

Easy

What is the outcome of executing the following React code (using Hooks)?

import React, { useState, useEffect } from 'react';

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;

    return () => {
      document.title = 'React App';
    };
  }, [count]);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click here
      </button>
    </div>
  );
}
Author: Vincent CotroStatus: PublishedQuestion passed 1405 times
Edit
7
Community EvaluationsNo one has reviewed this question yet, be the first!