Develop ultra fast with Prismane 🎉

useAnimation

useAnimation hook provides a simple way to manage animation state in your components.

Import

import { useAnimation } from "@prismane/core/hooks";

Usage

function Demo() {
  const { animating, animate, timing, duration } = useAnimation();

  return (
    <Flex direction="column" gap={fr(5)}>
      <Button onClick={() => animate()}>Toggle Animation</Button>
      <Animation
        w={fr(30)}
        h={fr(30)}
        bg="primary"
        animated={animating}
        timing={timing}
        duration={duration}
      />
    </Flex>
  );
}

Complex Usage

function Demo() {
  const { animating, animate, timing, duration } = useAnimation(
    true,
    750,
    "ease-in-out"
  );

  return (
    <Flex direction="column" gap={fr(5)}>
      <Button onClick={() => animate()}>Toggle Animation</Button>
      <Animation
        w={fr(30)}
        h={fr(30)}
        bg="primary"
        animated={animating}
        timing={timing}
        duration={duration}
      />
    </Flex>
  );
}

API

Parameters

NameTypeDescriptionDefault
initialbooleanThe initial state of the animation.false
durationnumberThe duration of the animation in milliseconds.150
timingstringThe timing function for the animation.ease

Return Value

NameTypeDescription
animatingbooleanRepresents the current animation state.
animate() => voidA function to toggle the animation state.
durationnumberThe duration of the animation in milliseconds.
timingstringThe timing function for the animation.