useState ➡️ 해당 내역이 바뀌면 렌더링 🟰 렌더링할 최소 단위에 붙이기

fadeIn, fadeOut animation

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeout {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

fadeInUp, fadeOutDown animation

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(-50%, 100%, 0);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes fadeOutDown {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate3d(-50%, 100%, 0);
  }
}

useRef로 animation style 변경하기

const closeIntroduce = (
  props: IntroduceProps,
  closeRef: React.RefObject<HTMLDivElement>
) => {
  const onAnimationEnd = () => {
    if (closeRef.current) {
      props.view[1](!props.view[0]); // 안보이게 바꾸기
      closeRef.current.removeEventListener('animationend', onAnimationEnd);
      // 애니메이션 끝나고 removeEventListener
    }
  };

  if (closeRef.current) {
    closeRef.current.addEventListener('animationend', onAnimationEnd);
    // animation 끝나면 onAnimationEnd 함수 실행
    closeRef.current.style.setProperty('animation', 'fadeout 0.7s forwards');
    // fadeout의 keyframe animation을 0.7초 실행한 후 'forwards'로 마지막 상태 유지
    // ➡️ 이거 안하면 다시 초기상태로 돌아감 🟰 안없어짐
  }
};

[React] 버튼을 이용해 컴포넌트 전환하기

React 외부 영역 클릭 시 닫기

React ref 를 통해서 style 설정하기

(즐거웅코드) CSS 아래에서 위로 올라오며 페이드인(fade in) 되는 애니메이션

CSS animation 구현시 마지막 상태 유지하는 방법