728x90
반응형
Install Package
npm i lottie-react
아래 링크에서 원하는 로티 파일 다운로드 후 코드를 작성합니다. (파일을 직접 다운로드하지 않고 URL 사용도 가능)
LottieFiles: Download Free lightweight animations for website & apps.
Effortlessly bring the smallest, free, ready-to-use motion graphics for the web, app, social, and designs. Create, edit, test, collaborate, and ship Lottie animations in no time!
lottiefiles.com
간단하게 로그인 성공 후 애니메이션을 1.5초 동안 출력하도록 구현해주었습니다.
import Lottie from "lottie-react";
import Success from "@/assets/lottie/Success.json";
// ...
const Login = () => {
const [isLoginSuccess, setisLoginSuccess] = useState(false);
const handleLogin = async () => {
try {
// ... 로그인 메서드
setIsLoginSuccess(true);
setTimeout(() => {
navigate("/redirect-page");
}, 1500);
} catch (error) {
// ...
}
};
return (
<>
{isLoginSuccess ? (
<div className="w-56 h-56 mx-auto my-auto">
<Lottie
animationData={Success} // 여기에 원하는 애니메이션 파일 적용
loop={false}
autoplay={true}
/>
</div>
) : (
// ...
'Category > React' 카테고리의 다른 글
| ReactNode란? (0) | 2025.03.10 |
|---|---|
| React Router에서 navigate와 Link의 차이점 이해하기 (0) | 2024.11.14 |
| 리액트 훅 useEffect와 useRef (1) | 2024.11.12 |
| React Router 버전과 구현 스타일에 따른 차이 비교 (0) | 2024.11.12 |
| React - 함수형 컴포넌트에서 라이프사이클 구현하는 법 (0) | 2024.11.11 |