1. react-lottie 설치
yarn add react-lottie --save --dev
2. 디자이너분께 lottie json 받기
3. 아래와 같이 작성
import React from 'react';
import Lottie from 'react-lottie';
import classNames from 'classnames/bind';
import { hot } from 'react-hot-loader/root';
import * as bear from '../../lottie/bear';
const style = require('./index.scss');
const cx = classNames.bind(style);
const lottieOptions = {
animationData: bear,
loop: true,
autoplay: true,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice'
}
};
const SaveProgress = () => {
return (
<div className={cx('save_progress')}>
<Lottie
options={lottieOptions}
isClickToPauseDisabled={false}
width={ 75 }
height={ 75 }
/>
</div>
);
}
export default hot(SaveProgress);
여기까지는 공식문서..
https://www.npmjs.com/package/react-lottie
react-lottie
lottie animation view for React
www.npmjs.com
띠용 에러 발생
다음과 같이 lottie/bear를 require로 import 하면 문제 해결
import React from 'react';
import Lottie from 'react-lottie';
import classNames from 'classnames/bind';
import { hot } from 'react-hot-loader/root';
const bear = require('../../lottie/bear');
// import * as bear from '../../lottie/bear';
const style = require('./index.scss');
const cx = classNames.bind(style);
const lottieOptions = {
animationData: bear,
loop: true,
autoplay: true,
rendererSettings: {
preserveAspectRatio: 'xMidYMid slice'
}
};
const SaveProgress = () => {
return (
<div className={cx('save_progress')}>
<Lottie
options={lottieOptions}
isClickToPauseDisabled={false}
width={ 75 }
height={ 75 }
/>
</div>
);
}
export default hot(SaveProgress);
'JavaScript > React.js' 카테고리의 다른 글
typescript 환경일 때 storybook 적용하기 (0) | 2020.06.10 |
---|---|
BrowserRouter에서 path를 직접 접근할 때 발생하는 이슈 (0) | 2020.03.13 |
리액트 LifeCycle (0) | 2019.05.02 |
리액트 16.3 Context API 파헤치기 (0) | 2019.04.22 |
Reselect를 이용하여 React와 Redux 최적화하기 (0) | 2019.04.17 |