npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@team-griffin/react-transition

v1.0.0

Published

Basic usage: ```tsx import Transition from '@team-griffin/react-transition';

Downloads

108

Readme

react-transition

Basic usage:

import Transition from '@team-griffin/react-transition';

<Transition>
  <Child/>
</Transition>

It also works out the box with list-style children:

<Transition>
  <Child1 key="1"/>
  <Child2 key="2"/>
  <Child3 key="3"/>
</Transition>

It's important to provide a key for each child as we use this to determine which list items have updated between renders.

props

duration

The animation duration. Defaults to 250.

<Transition duration={1000}>
  <Child/>
</Transition>

render

This is a render function that actually sets the css styles. It is given the following props:

{
  enter: boolean, // true when the component is first mounted
  entering: boolean, // true during the transition period
  entered: boolean, // true when the transition period has ended
  leave: boolean, // true when the component is about to unmount
  leaving: boolean, // true during the transition period
  left: boolean, // true when the component has unounted
  duration: number,
  children: ReactNode,
}

A typical example of a render function would look something like this:

const render = ({
  enter,
  entering,
  entered,
  leave,
  leaving,
  left,
  children,
  duration,
}) => {
  const styles = {
    transition: `all ${duration}ms`,
    opacity: (entering || entered || leave) ? 1 : 0,
  };

  return <div style={styles}>{children}</div>
};

<Transition render={render}>
  <Child/>
</Transition>

component

An element must wrap the transition in order to track the dom state. You can pass in a string for a native dom elment i.e. span or div.

<Transition component="span">
  <Child/>
</Transition>

If you want to pass in a component, you need to be able to accept a ref and apply it to an element. For example:

import { forwardRef } from 'react';

const Wrapper = forwardRef(({ children }, ref) => (
  <div ref={ref}>
    {children}
  </div>
))

So what makes this different to other transition libraries? It all lies in the unmounting logic. If you drop a component, usually the component is retained and rendered with the previous props for the duration of the transition. However, this all falls apart when you have nested components that have their own state or rely on redux state.

<Transition>
  <ConnectedChild/>
</Transition>

If your child component assumes it will only be rendered when certain global state is set, then if you continue to re-render it during a transition phase, when the global state is no longer available, it wall probably collapse.

We actually get around this problem by stashing the child's dom node, and rendering a static version of the component when it unmounts. Magic.