Created
February 27, 2021 18:31
-
-
Save stephepush/553c7dc2affca0eb06c8648966e36685 to your computer and use it in GitHub Desktop.
Hooks Practice Pluralsight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ImageToggleOnMouseOver from "../src/ImageToggleOnMouseOver"; | |
const ImageChangeOnMouseOver = () => { | |
return ( | |
<div> | |
<ImageToggleOnMouseOver | |
primaryImg="/static/speakers/bw/bmwFiverbw.jpg" | |
secondaryImg="/static/speakers/bmwFiver.jpg" | |
alt="" /> | |
| |
<ImageToggleOnMouseOver | |
primaryImg="/static/speakers/bw/OIPbw.jpg" | |
secondaryImg="/static/speakers/OIP.jpg" | |
alt="" /> | |
</div> | |
); | |
}; | |
export default ImageChangeOnMouseOver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useRef} from "react"; | |
const ImageToggleOnMouseOver = ({ primaryImg, secondaryImg }) => { | |
const imageRef = useRef(null); | |
return ( | |
<img onMouseOver={() => {imageRef.current.src = secondaryImg;}} | |
onMouseOut={() => {imageRef.current.src = primaryImg;}} | |
src={primaryImg} | |
alt="" ref={imageRef} | |
/> | |
) | |
} | |
export default ImageToggleOnMouseOver; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment