Created
December 5, 2025 00:49
-
-
Save remarkablemark/226ec9d6993960f2e8adfdb36df5eee8 to your computer and use it in GitHub Desktop.
React hook useFadeIn
This file contains hidden or 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 { useEffect, useState } from "react"; | |
| /** | |
| * Trigger animation after component mounts with a slight delay for dramatic effect | |
| * | |
| * @param delay - The delay in milliseconds | |
| * @returns A boolean indicating whether the element is visible | |
| */ | |
| function useFadeIn(delay) { | |
| const [isVisible, setIsVisible] = useState(false); | |
| useEffect(() => { | |
| const timer = setTimeout(() => setIsVisible(true), delay); | |
| return () => clearTimeout(timer); | |
| }, [delay]); | |
| return isVisible; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment