Rocky_Mountain_Vending/.pnpm-store/v10/files/04/51a3c94ea20e8958ec7f959d11ee7aa3afd1c48297b96fa2142f1483470e256b61ed9c74fbcccde2f4e2a983d8aede6b9b03810502bee6510b66f6e9a30144
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

48 lines
1.2 KiB
Text

/**
* Unmemoized version of {@link useRefToCallback}
* @see {@link useRefToCallback}
* @param ref
*/
export function refToCallback(ref) {
return function (newValue) {
if (typeof ref === 'function') {
ref(newValue);
}
else if (ref) {
ref.current = newValue;
}
};
}
var nullCallback = function () { return null; };
// lets maintain a weak ref to, well, ref :)
// not using `kashe` to keep this package small
var weakMem = new WeakMap();
var weakMemoize = function (ref) {
var usedRef = ref || nullCallback;
var storedRef = weakMem.get(usedRef);
if (storedRef) {
return storedRef;
}
var cb = refToCallback(usedRef);
weakMem.set(usedRef, cb);
return cb;
};
/**
* Transforms a given `ref` into `callback`.
*
* To transform `callback` into ref use {@link useCallbackRef|useCallbackRef(undefined, callback)}
*
* @param {ReactRef} ref
* @returns {Function}
*
* @see https://github.com/theKashey/use-callback-ref#reftocallback
*
* @example
* const ref = useRef(0);
* const setRef = useRefToCallback(ref);
* 👉 setRef(10);
* ✅ ref.current === 10
*/
export function useRefToCallback(ref) {
return weakMemoize(ref);
}