Files
url_tracker_tool/node_modules/@chakra-ui/hooks/dist/cjs/use-controllable-state.cjs
Andrei 58f8093689 Rebrand from 'Redirect Intelligence v2' to 'URL Tracker Tool V2' throughout UI
- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
2025-08-19 19:12:23 +00:00

43 lines
1.3 KiB
JavaScript

'use client';
'use strict';
var react = require('react');
var useCallbackRef = require('./use-callback-ref.cjs');
function useControllableProp(prop, state) {
const controlled = typeof prop !== "undefined";
const value = controlled ? prop : state;
return react.useMemo(() => [controlled, value], [controlled, value]);
}
function useControllableState(props) {
const {
value: valueProp,
defaultValue,
onChange,
shouldUpdate = (prev, next) => prev !== next
} = props;
const onChangeProp = useCallbackRef.useCallbackRef(onChange);
const shouldUpdateProp = useCallbackRef.useCallbackRef(shouldUpdate);
const [uncontrolledState, setUncontrolledState] = react.useState(defaultValue);
const controlled = valueProp !== void 0;
const value = controlled ? valueProp : uncontrolledState;
const setValue = useCallbackRef.useCallbackRef(
(next) => {
const setter = next;
const nextValue = typeof next === "function" ? setter(value) : next;
if (!shouldUpdateProp(value, nextValue)) {
return;
}
if (!controlled) {
setUncontrolledState(nextValue);
}
onChangeProp(nextValue);
},
[controlled, onChangeProp, value, shouldUpdateProp]
);
return [value, setValue];
}
exports.useControllableProp = useControllableProp;
exports.useControllableState = useControllableState;