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

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

Go to download

A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.

The newest version!
'use client';
'use strict';

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

const react = require('react');

function useEvent(callback, opts = {}) {
  const { sync = false } = opts;
  const callbackRef = useLatestRef(callback);
  return react.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 = react.useRef(value);
  ref.current = value;
  return ref;
}

exports.useEvent = useEvent;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy