Socket
Socket
Sign inDemoInstall

@rot1024/use-transition

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rot1024/use-transition

React Hooks for transition animation like Transition component in react-transition-group


Version published
Maintainers
1
Created

Readme

Source

@rot1024/use-transition

React Hooks for transition animation like Transition component in react-transition-group, but improves smooth transition

Transition component in react-transition-group, and use-transition are very nice. But they are incompatible with styled-components or Emotion, particularly with mountOnEnter or unmountOnExit.

In addition, react-transition-group and use-transition have incorrect transition duration when the transition direction is changed during the transition.

This library improves their problems. Following image is comparision of the libraries.

comparison

Usage

npm install --dev @rot1024/use-transition
# or
yarn add @rot1024/use-transition
import { useState } from "react";
import { styled } from "styled-components";
import useTransition from "@rot1024/use-transition";

const StyledDiv = styled.div`
  transition: ${({ state }) => state === "entering" || state === "exiting" ? "all 1s ease" : ""};
  opacity: ${({ state }) => state === "entering" || state === "entered" ? 1 : 0};
`;

const Component = () => {
  const [isActive, setActive] = useState(false);
  const state = useTransition(isActive, 1000, {
    mountOnEnter: true,
    unmountOnExit: true
  });
  // state is "entering", "entered", "exiting", "exited", or "unmounted"

  const handleClick = useCallback(() => {
    setActive(active => !active);
  }, [isActive, setActive])

  return (
    <div>
      <button onClick={handleClick}>Toggle</button>
      {state === "unmounted" ? null : <StyledDiv state={state}>Transition</StyledDiv>}
    </div>
  );
};

License

MIT License

FAQs

Last updated on 04 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc