Giter Club home page Giter Club logo

matissue's Introduction

😎 ynnsuis

즐기는 허접 개발자

✨ Skill

JS, TS, React, React-Native, Next

⚙️ OpenSource

matissue's People

Contributors

h0onnn avatar kimdonggyun1 avatar limeorange avatar lovesienna avatar sossost avatar yubinshin avatar

Watchers

 avatar

matissue's Issues

Variant Selector을 커스텀훅으로 만들경우 transition이 적용이 안됨

import { useState } from "react";
import { useRecoilValue } from "recoil";
import styled, { css } from "styled-components";
import darkModeAtom from "../store/darkModeAtom";

type Variant = "아이디" | "비밀번호";

const useVariantSelector = () => {
  const [variant, setVariant] = useState<Variant>("아이디");
  const isDarkMode = useRecoilValue(darkModeAtom);

  const VariantSelector = () => {
    return (
      <VariantWrapper>
        <VariantBox>
          <VariantBoxItem
            active={variant === "아이디"}
            onClick={() => {
              setVariant("아이디");
            }}
          >
            아이디 찾기
          </VariantBoxItem>
          <VariantBoxItem
            active={variant === "비밀번호"}
            onClick={() => {
              setVariant("비밀번호");
            }}
          >
            비밀번호 찾기
          </VariantBoxItem>
        </VariantBox>
        <VariantNoticeBar variant={variant} isDarkMode={isDarkMode} />
      </VariantWrapper>
    );
  };
  return { VariantSelector, variant };
};

export default useVariantSelector;

const VariantWrapper = styled.div`
  width: 100%;
`;

const VariantBox = styled.div`
  font-size: 16px;
  width: 100%;
  display: flex;
`;

const VariantBoxItem = styled.div<{ active: boolean }>`
  width: 50%;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  font-weight: 400;

  ${(props) =>
    props.active &&
    css`
      font-weight: 600;
    `};
`;

const VariantNoticeBar = styled.div<{ variant: Variant; isDarkMode: boolean }>`
  width: 50%;
  border-bottom: 0.3rem solid
    ${(props) =>
      props.isDarkMode ? props.theme.lightYellow : props.theme.yellow};
  transform: translateX(
    ${(props) => (props.variant === "아이디" ? "0" : "100%")}
  );
  transition: transform 0.3s;
`;

커스텀 훅으로 분리하기 이전엔 멀쩡히 작동되던 transition이 먹통이 되었다..

커스텀훅의 컴포넌트를 리턴해서 쓰는건 리렌더링 방식이 다른건가...? 상태값 업데이트에따른 동작은 다 정상적으로 작동하는데 트랜지션만 먹통이된다...

왜인지 아무리 고민을해도 잘모르겠다.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.