@tamagui/use-controllable-state 1.74.3 → 1.74.5

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.
@@ -0,0 +1,2 @@
1
+ export * from "./useControllableState";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "mappings": "AAAA,cAAc;",
5
+ "names": []
6
+ }
@@ -0,0 +1,37 @@
1
+ import { useEvent } from "@tamagui/use-event";
2
+ import { startTransition, useEffect, useRef, useState } from "react";
3
+ const emptyCallbackFn = (_) => _();
4
+ function useControllableState({
5
+ prop,
6
+ defaultProp,
7
+ onChange,
8
+ strategy = "prop-wins",
9
+ preventUpdate,
10
+ transition
11
+ }) {
12
+ const [state, setState] = useState(prop ?? defaultProp), previous = useRef(state), propWins = strategy === "prop-wins" && prop !== void 0, value = propWins ? prop : state, onChangeCb = useEvent(onChange || idFn), transitionFn = transition ? startTransition : emptyCallbackFn;
13
+ useEffect(() => {
14
+ prop !== void 0 && (previous.current = prop, transitionFn(() => {
15
+ setState(prop);
16
+ }));
17
+ }, [prop]), useEffect(() => {
18
+ propWins || state !== previous.current && (previous.current = state, onChangeCb(state));
19
+ }, [onChangeCb, state, propWins]);
20
+ const setter = useEvent((next) => {
21
+ if (!preventUpdate)
22
+ if (propWins) {
23
+ const nextValue = typeof next == "function" ? next(previous.current) : next;
24
+ onChangeCb(nextValue);
25
+ } else
26
+ transitionFn(() => {
27
+ setState(next);
28
+ });
29
+ });
30
+ return [value, setter];
31
+ }
32
+ const idFn = () => {
33
+ };
34
+ export {
35
+ useControllableState
36
+ };
37
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useControllableState.ts"],
4
+ "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAgB,iBAAiB,WAAW,QAAQ,gBAAgB;AAOpE,MAAM,kBAAkB,CAAC,MAAM,EAAE;AAE1B,SAAS,qBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAOiD;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,QAAQ,WAAW,GAChD,WAAW,OAAY,KAAK,GAC5B,WAAW,aAAa,eAAe,SAAS,QAChD,QAAQ,WAAW,OAAO,OAC1B,aAAa,SAAS,YAAY,IAAI,GAEtC,eAAe,aAAa,kBAAkB;AAEpD,YAAU,MAAM;AACd,IAAI,SAAS,WACb,SAAS,UAAU,MACnB,aAAa,MAAM;AACjB,eAAS,IAAI;AAAA,IACf,CAAC;AAAA,EACH,GAAG,CAAC,IAAI,CAAC,GAET,UAAU,MAAM;AACd,IAAI,YACA,UAAU,SAAS,YACrB,SAAS,UAAU,OACnB,WAAW,KAAK;AAAA,EAEpB,GAAG,CAAC,YAAY,OAAO,QAAQ,CAAC;AAEhC,QAAM,SAAS,SAAS,CAAC,SAAS;AAChC,QAAI;AACJ,UAAI,UAAU;AACZ,cAAM,YAAY,OAAO,QAAS,aAAa,KAAK,SAAS,OAAO,IAAI;AACxE,mBAAW,SAAS;AAAA,MACtB;AACE,qBAAa,MAAM;AACjB,mBAAS,IAAI;AAAA,QACf,CAAC;AAAA,EAEL,CAAC;AAED,SAAO,CAAC,OAAY,MAAM;AAC5B;AAEA,MAAM,OAAO,MAAM;AAAC;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-controllable-state",
3
- "version": "1.74.3",
3
+ "version": "1.74.5",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -28,13 +28,13 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@tamagui/use-event": "1.74.3"
31
+ "@tamagui/use-event": "1.74.5"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "*"
35
35
  },
36
36
  "devDependencies": {
37
- "@tamagui/build": "1.74.3",
37
+ "@tamagui/build": "1.74.5",
38
38
  "react": "^18.2.0"
39
39
  },
40
40
  "publishConfig": {