use-computed.mjs 579 B

12345678910111213141516171819
  1. import { collectMotionValues } from 'motion-dom';
  2. import { useCombineMotionValues } from './use-combine-values.mjs';
  3. function useComputed(compute) {
  4. /**
  5. * Open session of collectMotionValues. Any MotionValue that calls get()
  6. * will be saved into this array.
  7. */
  8. collectMotionValues.current = [];
  9. compute();
  10. const value = useCombineMotionValues(collectMotionValues.current, compute);
  11. /**
  12. * Synchronously close session of collectMotionValues.
  13. */
  14. collectMotionValues.current = undefined;
  15. return value;
  16. }
  17. export { useComputed };