Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 번들 크기 개선 - 1 #434

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
eonseok-jeon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"axios": "^1.6.8",
"date-fns": "^3.6.0",
"firebase": "^10.12.4",
"lottie-react": "^2.4.0",
"lottie-web": "^5.12.2",
"nanoid": "^5.0.7",
"react": "^18.2.0",
"react-daum-postcode": "^3.1.3",
Expand All @@ -49,6 +49,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"prettier": "^3.2.5",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
Expand Down
3 changes: 1 addition & 2 deletions src/views/loadings/BigLoding/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Lottie from 'lottie-react';

import { container, loadingText, wrapper } from './style.css';
import Lottie from '../Lottie';
import mainLoading from '../lotties/mainLoading.json';

const BigLoading = () => {
Expand Down
5 changes: 2 additions & 3 deletions src/views/loadings/ButtonLoading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Lottie from 'lottie-react';

import Lottie from '../Lottie';
import buttonLoadingWhite from '../lotties/buttonLoadingWhite.json';

const ButtonLoading = ({ width, height = 28 }: { width: number | undefined; height?: number }) => {
return <Lottie animationData={buttonLoadingWhite} style={{ width: width, height }} />;
return <Lottie animationData={buttonLoadingWhite} style={{ width, height }} />;
};

export default ButtonLoading;
45 changes: 45 additions & 0 deletions src/views/loadings/Lottie/index.tsx
eonseok-jeon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { type AnimationConfigWithData, type AnimationItem } from 'lottie-web';
import lottie from 'lottie-web/build/player/lottie_light';
import { type CSSProperties, useEffect, useRef } from 'react';

const Lottie = ({ animationData, style }: { animationData: unknown; style?: CSSProperties }) => {
const animationInstanceRef = useRef<AnimationItem>();
const animationContainer = useRef<HTMLDivElement>(null);

const loadAnimation = () => {
// Return if the container ref is null
if (!animationContainer.current) {
return;
}

// Destroy any previous instance
animationInstanceRef.current?.destroy();

// Build the animation configuration
const config: AnimationConfigWithData = {
animationData,
container: animationContainer.current,
};

// Save the animation instance
animationInstanceRef.current = lottie.loadAnimation(config);

// Return a function that will clean up
return () => {
animationInstanceRef.current?.destroy();
animationInstanceRef.current = undefined;
};
};

useEffect(() => {
const onUnmount = loadAnimation();

// Clean up on unmount
return () => onUnmount?.();
// eslint-disable-next-line
}, [animationData]);

return <div ref={animationContainer} style={style} />;
};

export default Lottie;
3 changes: 1 addition & 2 deletions src/views/loadings/SmallLoading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Lottie from 'lottie-react';

import { container, loadingText, wrapper } from './style.css';
import Lottie from '../Lottie';
import mainLoading from '../lotties/mainLoading.json';

const SmallLoading = () => {
Expand Down
Loading