@reactuses/core 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +30 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2428,9 +2428,39 @@ function useFocus(target, initialValue = false) {
|
|
|
2428
2428
|
return [focus, setFocus];
|
|
2429
2429
|
}
|
|
2430
2430
|
|
|
2431
|
+
function useControlled({
|
|
2432
|
+
controlled,
|
|
2433
|
+
defaultValue: defaultProp,
|
|
2434
|
+
state = "value"
|
|
2435
|
+
}) {
|
|
2436
|
+
const { current: isControlled } = react.useRef(controlled !== void 0);
|
|
2437
|
+
const [valueState, setValue] = react.useState(defaultProp);
|
|
2438
|
+
const value = isControlled ? controlled : valueState;
|
|
2439
|
+
react.useEffect(() => {
|
|
2440
|
+
if (isControlled !== (controlled !== void 0)) {
|
|
2441
|
+
console.error(
|
|
2442
|
+
[
|
|
2443
|
+
`A component is changing the ${isControlled ? "" : "un"}controlled ${state} state of ${name} to be ${isControlled ? "un" : ""}controlled.`,
|
|
2444
|
+
"Elements should not switch from uncontrolled to controlled (or vice versa).",
|
|
2445
|
+
`Decide between using a controlled or uncontrolled ${name} element for the lifetime of the component.`,
|
|
2446
|
+
"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.",
|
|
2447
|
+
"More info: https://fb.me/react-controlled-components"
|
|
2448
|
+
].join("\n")
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2451
|
+
}, [state, controlled]);
|
|
2452
|
+
const setValueIfUncontrolled = react.useCallback((newValue) => {
|
|
2453
|
+
if (!isControlled) {
|
|
2454
|
+
setValue(newValue);
|
|
2455
|
+
}
|
|
2456
|
+
}, []);
|
|
2457
|
+
return [value, setValueIfUncontrolled];
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2431
2460
|
exports.useActiveElement = useActiveElement;
|
|
2432
2461
|
exports.useClickOutside = useClickOutSide;
|
|
2433
2462
|
exports.useClipboard = useClipBorad;
|
|
2463
|
+
exports.useControlled = useControlled;
|
|
2434
2464
|
exports.useCounter = useCounter;
|
|
2435
2465
|
exports.useCustomCompareEffect = useCustomCompareEffect;
|
|
2436
2466
|
exports.useCycleList = useCycleList;
|
package/dist/index.d.ts
CHANGED
|
@@ -712,4 +712,11 @@ declare function useCycleList<T>(list: T[], i?: number): readonly [T, (i?: numbe
|
|
|
712
712
|
|
|
713
713
|
declare function useFocus(target: BasicTarget<HTMLElement | SVGElement>, initialValue?: boolean): readonly [boolean, (value: boolean) => void];
|
|
714
714
|
|
|
715
|
-
|
|
715
|
+
interface IProps<T> {
|
|
716
|
+
controlled?: T;
|
|
717
|
+
defaultValue?: T;
|
|
718
|
+
state?: T;
|
|
719
|
+
}
|
|
720
|
+
declare function useControlled<T = string>({ controlled, defaultValue, state, }: IProps<T>): readonly [T, (newValue: T) => void];
|
|
721
|
+
|
|
722
|
+
export { useActiveElement, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFocus, _default as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, _default$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$3 as useUpdateEffect, _default$2 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
|
package/dist/index.mjs
CHANGED
|
@@ -2424,4 +2424,33 @@ function useFocus(target, initialValue = false) {
|
|
|
2424
2424
|
return [focus, setFocus];
|
|
2425
2425
|
}
|
|
2426
2426
|
|
|
2427
|
-
|
|
2427
|
+
function useControlled({
|
|
2428
|
+
controlled,
|
|
2429
|
+
defaultValue: defaultProp,
|
|
2430
|
+
state = "value"
|
|
2431
|
+
}) {
|
|
2432
|
+
const { current: isControlled } = useRef(controlled !== void 0);
|
|
2433
|
+
const [valueState, setValue] = useState(defaultProp);
|
|
2434
|
+
const value = isControlled ? controlled : valueState;
|
|
2435
|
+
useEffect(() => {
|
|
2436
|
+
if (isControlled !== (controlled !== void 0)) {
|
|
2437
|
+
console.error(
|
|
2438
|
+
[
|
|
2439
|
+
`A component is changing the ${isControlled ? "" : "un"}controlled ${state} state of ${name} to be ${isControlled ? "un" : ""}controlled.`,
|
|
2440
|
+
"Elements should not switch from uncontrolled to controlled (or vice versa).",
|
|
2441
|
+
`Decide between using a controlled or uncontrolled ${name} element for the lifetime of the component.`,
|
|
2442
|
+
"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.",
|
|
2443
|
+
"More info: https://fb.me/react-controlled-components"
|
|
2444
|
+
].join("\n")
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
}, [state, controlled]);
|
|
2448
|
+
const setValueIfUncontrolled = useCallback((newValue) => {
|
|
2449
|
+
if (!isControlled) {
|
|
2450
|
+
setValue(newValue);
|
|
2451
|
+
}
|
|
2452
|
+
}, []);
|
|
2453
|
+
return [value, setValueIfUncontrolled];
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
export { useActiveElement, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps$1 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMediaDevices$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
|