0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

react-transition-group使ってみた

Last updated at Posted at 2022-11-24
import { useState } from "react";
import { CSSTransition } from "react-transition-group";
import styled from "@emotion/styled";

const MyStyles = styled.div`
    .fade-enter-done {
      background: red;
      height: 100px;
    }
    
    .fade-enter {
      height: 0;
      overflow: hidden;
    }

    .fade-enter-active {
      transition: height 1s;
      background: green;
      height: 100px;
    }
`;

export const  App = () => {
  const [animate, setAnimate] = useState(false);
  return (
    <MyStyles>
      <button onClick={() => setAnimate((prev) => !prev)}>
        {animate ? "falseにする" : "trueにする"}
      </button>
      <CSSTransition classNames="fade" in={animate} timeout={1000} unmountOnExit>
        {(state) => {
          return <h1>{state}</h1>;
        }}
      </CSSTransition>
    </MyStyles>
  );
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?