Skip to content

Animate the addition, removal and shuffling of elements using css transitions with the react-mixitup component

License

Notifications You must be signed in to change notification settings

ricsam/react-mixitup

Repository files navigation

react-mixitup

Animate the addition, removal and shuffling of elements in react.

GitHub Repo stars

Edit in CodeSandbox

Getting Started

Install react-mixitup

npm install --save react-mixitup

npm npm

import { ReactMixitup } from 'react-mixitup';

function Example() {
  const [keys, setKeys] = React.useState([1,2,3]);

  return (
    <div style={{ height: 64 }}>
      <button onClick={() => {
        setKeys(keys[0] === 1 ? [3,2,1] : [1,2,3]);
      }}>
        Mixitup
      </button>
      <ReactMixitup
        keys={keys}
        renderCell={(key, style, ref) => (
          <div
            key={key}
            ref={ref}
            style={{
              // You must set the transition property here!
              transition: 'transform 300ms linear',
              ...style,
            }}
          >
            {key}
          </div>
        )}
        renderWrapper={(style, ref, cells) => {
          return (
            <div
              style={{
                transition: 'height 300ms ease',
                display: 'flex',
                ...style
              }}
              ref={ref}
            >
              {cells}
            </div>
          );
        }}
        dynamicDirection="horizontal"
        transitionDuration={300}
      />
    </div>
  )
}

License

MIT © ricsam