如何在React JS中悬停第一个DIV之后,如何用另一个DIV替换DIV(反之亦然)
#javascript #css #react #vite
import React, { useState } from 'react';

function App() {
  const [isHovered, setIsHovered] = useState(false);

  const handleHover = () => {
    setIsHovered(true);
  };

  const handleLeave = () => {
    setIsHovered(false);
  };

  return (
    <div>
      {isHovered ? (
        <div
          onMouseEnter={handleHover}
          onMouseLeave={handleLeave}
        >
          {/* Content of the first div */}
          <h2>Hover over me</h2>
        </div>
      ) : (
        <div>
          {/* Content of the second div */}
          <h2>Hovered!</h2>
        </div>
      )}
    </div>
  );
}

export default App;