728x90
μ’ μ€ κ°λ° μ€μ νλ©΄ μ ν ν¨κ³Όκ° μμΌλ©΄ μ’μ κ² κ°μ λ£μ΄λ³Έ fade ν¨κ³Ό μ»΄ν¬λνΈμ λλ€.
duration λ³μλ‘ fade in μκ° μ‘°μ κ°λ₯νκ³ ,
μ ν μ λλ©μ΄μ μν μμ±μ μλ μ°Έκ³ .
entering: μ»΄ν¬λνΈκ° νλ©΄μ μ§μ νλ μ λλ©μ΄μ μ μν μ€μΈ μνλ₯Ό λνλ λλ€.
entered: μ»΄ν¬λνΈκ° νλ©΄μ μμ ν μ§μ ν μνλ₯Ό λνλ λλ€.
exiting: μ»΄ν¬λνΈκ° νλ©΄μμ μ¬λΌμ§λ μ λλ©μ΄μ μ μν μ€μΈ μνλ₯Ό λνλ λλ€.
exited: μ»΄ν¬λνΈκ° νλ©΄μμ μμ ν μ¬λΌμ§ μνλ₯Ό λνλ λλ€.
νΉμ λμ€μ μ¨λ¨Ήμ μΌ μκΈΈκΉλ΄ & νμνμ λΆ μμκΉλ΄ 곡μ !
μ μ°Έκ³ λ‘ reactμμ transition μ°λ €λ©΄ μ€μΉ λ¨Όμ ν΄μ€μΌνλ€.
Javascript :
npm install react-transition-group
Typescript :
npm i --save-dev @types/react-transition-group
Fade in/Fade out/λΆλλ¬μ΄ νλ©΄μ ν μ½λ
import React, { ReactNode } from "react";
import { Transition } from "react-transition-group";
interface IProps {
children: React.ReactNode;
}
const duration = 200;
const defaultStyle = {
transition: `opacity ${duration}ms ease-in-out`,
opacity: 0,
};
const transitionStyles: { [key: string]: any } = {
entering: { opacity: 1 },
entered: { opacity: 1 },
exiting: { opacity: 0 },
exited: { opacity: 0 },
};
const Fade = ({ children }: IProps) => {
const [inProp, setInProp] = React.useState(false);
React.useEffect(() => {
setInProp(true);
return () => setInProp(false);
}, []);
return (
<Transition in={inProp} timeout={duration}>
{(state) => (
<div
style={{
...defaultStyle,
...transitionStyles[state],
}}
>
{children}
</div>
)}
</Transition>
);
};
export default Fade;
μ¬μ©ν λλ μλμ κ°μ΄ return λ΄λΆμ fade ν¨κ³Όλ₯Ό μ£Όκ³ μΆμ μμλ€μ κ°μΈλ©΄ λ©λλ€.
728x90