Rocky_Mountain_Vending/.pnpm-store/v10/files/b2/d67c769d7e407a2cac33042add8d913555e035db99a91ad5127cc1a349f7512ab1f6d188fd507a1ca92dbe4324d16c5c559f9f01819af7f11d054fee467a60
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

47 lines
1.4 KiB
Text

// packages/react/use-controllable-state/src/useControllableState.tsx
import * as React from "react";
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
function useControllableState({
prop,
defaultProp,
onChange = () => {
}
}) {
const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange });
const isControlled = prop !== void 0;
const value = isControlled ? prop : uncontrolledProp;
const handleChange = useCallbackRef(onChange);
const setValue = React.useCallback(
(nextValue) => {
if (isControlled) {
const setter = nextValue;
const value2 = typeof nextValue === "function" ? setter(prop) : nextValue;
if (value2 !== prop) handleChange(value2);
} else {
setUncontrolledProp(nextValue);
}
},
[isControlled, prop, setUncontrolledProp, handleChange]
);
return [value, setValue];
}
function useUncontrolledState({
defaultProp,
onChange
}) {
const uncontrolledState = React.useState(defaultProp);
const [value] = uncontrolledState;
const prevValueRef = React.useRef(value);
const handleChange = useCallbackRef(onChange);
React.useEffect(() => {
if (prevValueRef.current !== value) {
handleChange(value);
prevValueRef.current = value;
}
}, [value, prevValueRef, handleChange]);
return uncontrolledState;
}
export {
useControllableState
};
//# sourceMappingURL=index.mjs.map