@tamagui/use-controllable-state
Advanced tools
Comparing version 1.125.6 to 1.125.7
@@ -1,2 +0,2 @@ | ||
export * from "./useControllableState"; | ||
//# sourceMappingURL=index.js.map | ||
export * from "./useControllableState.native.js"; | ||
//# sourceMappingURL=index.native.js.map |
import { useEvent } from "@tamagui/use-event"; | ||
import * as React from "react"; | ||
import { startTransition } from "@tamagui/start-transition"; | ||
var emptyCallbackFn = function(_) { | ||
var emptyCallbackFn = function (_) { | ||
return _(); | ||
}; | ||
function useControllableState(param) { | ||
var { prop, defaultProp, onChange, strategy = "prop-wins", preventUpdate, transition } = param, [state, setState] = React.useState(prop ?? defaultProp), previous = React.useRef(state), propWins = strategy === "prop-wins" && prop !== void 0, value = propWins ? prop : state, onChangeCb = useEvent(onChange || idFn), transitionFn = transition ? startTransition : emptyCallbackFn; | ||
React.useEffect(function() { | ||
prop !== void 0 && (previous.current = prop, transitionFn(function() { | ||
var { | ||
prop, | ||
defaultProp, | ||
onChange, | ||
strategy = "prop-wins", | ||
preventUpdate, | ||
transition | ||
} = param, | ||
[state, setState] = React.useState(prop ?? defaultProp), | ||
previous = React.useRef(state), | ||
propWins = strategy === "prop-wins" && prop !== void 0, | ||
value = propWins ? prop : state, | ||
onChangeCb = useEvent(onChange || idFn), | ||
transitionFn = transition ? startTransition : emptyCallbackFn; | ||
React.useEffect(function () { | ||
prop !== void 0 && (previous.current = prop, transitionFn(function () { | ||
setState(prop); | ||
})); | ||
}, [ | ||
prop | ||
]), React.useEffect(function() { | ||
}, [prop]), React.useEffect(function () { | ||
propWins || state !== previous.current && (previous.current = state, onChangeCb(state)); | ||
}, [ | ||
onChangeCb, | ||
state, | ||
propWins | ||
]); | ||
var setter = useEvent(function(next) { | ||
if (!preventUpdate) | ||
if (propWins) { | ||
var nextValue = typeof next == "function" ? next(previous.current) : next; | ||
onChangeCb(nextValue); | ||
} else | ||
transitionFn(function() { | ||
setState(next); | ||
}); | ||
}, [onChangeCb, state, propWins]); | ||
var setter = useEvent(function (next) { | ||
if (!preventUpdate) if (propWins) { | ||
var nextValue = typeof next == "function" ? next(previous.current) : next; | ||
onChangeCb(nextValue); | ||
} else transitionFn(function () { | ||
setState(next); | ||
}); | ||
}); | ||
return [ | ||
value, | ||
setter | ||
]; | ||
return [value, setter]; | ||
} | ||
var idFn = function() { | ||
}; | ||
export { | ||
useControllableState | ||
}; | ||
//# sourceMappingURL=useControllableState.js.map | ||
var idFn = function () {}; | ||
export { useControllableState }; | ||
//# sourceMappingURL=useControllableState.native.js.map |
{ | ||
"name": "@tamagui/use-controllable-state", | ||
"version": "1.125.6", | ||
"version": "1.125.7", | ||
"sideEffects": false, | ||
@@ -36,7 +36,7 @@ "source": "src/index.ts", | ||
"dependencies": { | ||
"@tamagui/start-transition": "1.125.6", | ||
"@tamagui/use-event": "1.125.6" | ||
"@tamagui/start-transition": "1.125.7", | ||
"@tamagui/use-event": "1.125.7" | ||
}, | ||
"devDependencies": { | ||
"@tamagui/build": "1.125.6", | ||
"@tamagui/build": "1.125.7", | ||
"react": "*" | ||
@@ -43,0 +43,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
28793
445
+ Added@tamagui/constants@1.125.7(transitive)
+ Added@tamagui/start-transition@1.125.7(transitive)
+ Added@tamagui/use-event@1.125.7(transitive)
- Removed@tamagui/constants@1.125.6(transitive)
- Removed@tamagui/start-transition@1.125.6(transitive)
- Removed@tamagui/use-event@1.125.6(transitive)
Updated@tamagui/use-event@1.125.7