@tamagui/use-controllable-state
Advanced tools
Comparing version 1.0.0-beta.193 to 1.0.0-beta.203
@@ -30,4 +30,5 @@ var __defProp = Object.defineProperty; | ||
onChange, | ||
strategy | ||
strategy = "prop-wins" | ||
}) { | ||
const currentProp = (0, import_react.useRef)(prop); | ||
const handleChange = (0, import_react_use_callback_ref.useCallbackRef)(onChange); | ||
@@ -37,2 +38,3 @@ const [val, setVal] = (0, import_react.useState)(prop ?? defaultProp); | ||
(0, import_react.useEffect)(() => { | ||
currentProp.current = prop; | ||
setVal((prev) => getNextStateWithCallback(prev, prop, handleChange)); | ||
@@ -43,3 +45,3 @@ }, [prop]); | ||
(0, import_react.useCallback)((next) => { | ||
if (propWins && prop !== void 0) { | ||
if (propWins && currentProp.current !== void 0) { | ||
return; | ||
@@ -46,0 +48,0 @@ } |
var __defProp = Object.defineProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
import { useCallbackRef } from "@radix-ui/react-use-callback-ref"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
function useControllableState({ | ||
@@ -9,4 +9,5 @@ prop, | ||
onChange, | ||
strategy | ||
strategy = "prop-wins" | ||
}) { | ||
const currentProp = useRef(prop); | ||
const handleChange = useCallbackRef(onChange); | ||
@@ -16,2 +17,3 @@ const [val, setVal] = useState(prop != null ? prop : defaultProp); | ||
useEffect(() => { | ||
currentProp.current = prop; | ||
setVal((prev) => getNextStateWithCallback(prev, prop, handleChange)); | ||
@@ -22,3 +24,3 @@ }, [prop]); | ||
useCallback((next) => { | ||
if (propWins && prop !== void 0) { | ||
if (propWins && currentProp.current !== void 0) { | ||
return; | ||
@@ -25,0 +27,0 @@ } |
var __defProp = Object.defineProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
import { useCallbackRef } from "@radix-ui/react-use-callback-ref"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
function useControllableState({ | ||
@@ -9,4 +9,5 @@ prop, | ||
onChange, | ||
strategy | ||
strategy = "prop-wins" | ||
}) { | ||
const currentProp = useRef(prop); | ||
const handleChange = useCallbackRef(onChange); | ||
@@ -16,2 +17,3 @@ const [val, setVal] = useState(prop != null ? prop : defaultProp); | ||
useEffect(() => { | ||
currentProp.current = prop; | ||
setVal((prev) => getNextStateWithCallback(prev, prop, handleChange)); | ||
@@ -22,3 +24,3 @@ }, [prop]); | ||
useCallback((next) => { | ||
if (propWins && prop !== void 0) { | ||
if (propWins && currentProp.current !== void 0) { | ||
return; | ||
@@ -25,0 +27,0 @@ } |
{ | ||
"name": "@tamagui/use-controllable-state", | ||
"version": "1.0.0-beta.193+14c13acd", | ||
"version": "1.0.0-beta.203+bdbb1f11", | ||
"sideEffects": false, | ||
@@ -28,3 +28,3 @@ "source": "src/index.ts", | ||
"devDependencies": { | ||
"@tamagui/build": "^1.0.0-beta.193+14c13acd", | ||
"@tamagui/build": "^1.0.0-beta.203+bdbb1f11", | ||
"react": "*", | ||
@@ -36,3 +36,3 @@ "react-dom": "*" | ||
}, | ||
"gitHead": "14c13acd9143e76d975e7a6c311d4a5f3a00bced" | ||
"gitHead": "bdbb1f11fae44e3a78133373ef108adccaa68924" | ||
} |
@@ -1,8 +0,8 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
export declare function useControllableState<T>({ prop, defaultProp, onChange, strategy, }: { | ||
prop?: T | undefined; | ||
defaultProp: T; | ||
onChange?: (next: T) => void; | ||
onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>; | ||
strategy?: 'prop-wins' | 'most-recent-wins'; | ||
}): [T, React.Dispatch<React.SetStateAction<T>>]; | ||
//# sourceMappingURL=useControllableState.d.ts.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
14322
176