
package.dist.utils.use-event.cjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
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