[React] React Hooks (7) - useFadeIn
2023. 2. 2. 20:11
프로그래밍/React
useFadeIn 서서히 나타나는 이벤트를 hooks로 만들어보기 useFadeIn 예시 3초 뒤 Hello, 15초 뒤 lorem ipsum...이 화면에 뜸 const useFadeIn = (duration = 1, delay = 0) => { if (typeof duration !== "number" || typeof delay !== "number") { return; } const element = useRef(); useEffect(() => { if (element.current) { const { current } = element; current.style.transition = `opacity ${duration}s ease-in-out ${delay}s`; current.style.o..