All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.utils.use-event.js Maven / Gradle / Ivy

'use client';
import { useCallback, useRef } from 'react';

function useEvent(callback, opts = {}) {
  const { sync = false } = opts;
  const callbackRef = useLatestRef(callback);
  return useCallback(
    // biome-ignore lint/suspicious/noExplicitAny: 
    (...args) => {
      if (sync) return queueMicrotask(() => callbackRef.current?.(...args));
      return callbackRef.current?.(...args);
    },
    [sync, callbackRef]
  );
}
function useLatestRef(value) {
  const ref = useRef(value);
  ref.current = value;
  return ref;
}

export { useEvent };




© 2015 - 2025 Weber Informatics LLC | Privacy Policy