use-animate.mjs 566 B

1234567891011121314151617
  1. import { useConstant } from '../../utils/use-constant.mjs';
  2. import { useUnmountEffect } from '../../utils/use-unmount-effect.mjs';
  3. import { createScopedAnimate } from '../animate/index.mjs';
  4. function useAnimate() {
  5. const scope = useConstant(() => ({
  6. current: null, // Will be hydrated by React
  7. animations: [],
  8. }));
  9. const animate = useConstant(() => createScopedAnimate(scope));
  10. useUnmountEffect(() => {
  11. scope.animations.forEach((animation) => animation.stop());
  12. });
  13. return [scope, animate];
  14. }
  15. export { useAnimate };