M. T. H. Titumir Posted on May 17, 2023 How to replace a div with another div after hovering first div in react js (and vice-versa) #react #css #javascript #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; Enter fullscreen mode Exit fullscreen mode Top comments (2) Subscribe Submit Preview Dismiss Collapse Expand Nwosa Tochukwu Nwosa Tochukwu Nwosa Tochukwu Follow A frontend (React) developer on a mission to build beautiful, user-friendly websites. Passionate about learning and growing in this exciting field...….. Email obere4u@gmail.com Location Nigeria Education Federal University of Technology, Owerri Pronouns He Work Frontend Developer at Kinplus Technologies Joined Aug 16, 2021 • May 17 '23 Dropdown menu Copy link Hide Bookmarked. Will utilize it in my project.. Thanks for sharing Collapse Expand M. T. H. Titumir M. T. H. Titumir M. T. H. Titumir Follow simplicity is the best Location Chattogram, Bangladesh Education B. Sc. in Mathematics (running) Work CEO & Founder at Perfumer's Den Joined Jan 17, 2023 • May 25 '23 Dropdown menu Copy link Hide My pleasure Code of Conduct • Report abuse
Top comments (2)
Bookmarked. Will utilize it in my project..
Thanks for sharing
My pleasure