@tamagui/use-controllable-state 1.0.10 → 1.0.12

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/cjs/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/dist/esm/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-controllable-state",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -27,14 +27,14 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@tamagui/use-event": "^1.0.10"
30
+ "@tamagui/use-event": "^1.0.12"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "*",
34
34
  "react-dom": "*"
35
35
  },
36
36
  "devDependencies": {
37
- "@tamagui/build": "^1.0.10",
37
+ "@tamagui/build": "^1.0.12",
38
38
  "react": "^18.2.0",
39
39
  "react-dom": "^18.2.0"
40
40
  },
package/dist/jsx/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./useControllableState";
2
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './useControllableState'\n"],
5
- "mappings": "AAAA;",
6
- "names": []
7
- }
@@ -1,39 +0,0 @@
1
- import { useEvent } from "@tamagui/use-event";
2
- import { useEffect, useRef, useState } from "react";
3
- function useControllableState({
4
- prop,
5
- defaultProp,
6
- onChange,
7
- strategy = "prop-wins",
8
- preventUpdate
9
- }) {
10
- const [state, setState] = useState(prop != null ? prop : defaultProp);
11
- const previous = useRef(state);
12
- const propWins = strategy === "prop-wins" && prop !== void 0;
13
- const value = propWins ? prop : state;
14
- const onChangeCb = useEvent(onChange || idFn);
15
- useEffect(() => {
16
- if (state !== previous.current) {
17
- previous.current = state;
18
- onChangeCb(state);
19
- }
20
- }, [onChangeCb, state]);
21
- const setter = useEvent((next) => {
22
- if (preventUpdate)
23
- return;
24
- console.log("setting", propWins, prop, next);
25
- if (propWins) {
26
- const nextValue = typeof next === "function" ? next(previous.current) : next;
27
- onChangeCb(nextValue);
28
- } else {
29
- setState(next);
30
- }
31
- });
32
- return [value, setter];
33
- }
34
- const idFn = () => {
35
- };
36
- export {
37
- useControllableState
38
- };
39
- //# sourceMappingURL=useControllableState.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/useControllableState.ts"],
4
- "sourcesContent": ["import { useEvent } from '@tamagui/use-event'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\n\n// can configure to allow most-recent-wins or prop-wins\n// defaults to prop-wins\n\ntype ChangeCb<T> = ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n preventUpdate,\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ChangeCb<T>\n strategy?: 'prop-wins' | 'most-recent-wins'\n preventUpdate?: boolean\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const [state, setState] = useState(prop ?? defaultProp)\n const previous = useRef<any>(state)\n const propWins = strategy === 'prop-wins' && prop !== undefined\n const value = propWins ? prop : state\n const onChangeCb = useEvent(onChange || idFn)\n\n useEffect(() => {\n if (state !== previous.current) {\n previous.current = state\n onChangeCb(state)\n }\n }, [onChangeCb, state])\n\n const setter = useEvent((next) => {\n if (preventUpdate) return\n console.log('setting', propWins, prop, next)\n if (propWins) {\n const nextValue = typeof next === 'function' ? next(previous.current) : next\n onChangeCb(nextValue)\n } else {\n setState(next)\n }\n })\n\n return [value as T, setter]\n}\n\nconst idFn = () => {}\n"],
5
- "mappings": "AAAA;AACA;AAOO,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,GAO+C;AAC/C,QAAM,CAAC,OAAO,YAAY,SAAS,sBAAQ,WAAW;AACtD,QAAM,WAAW,OAAY,KAAK;AAClC,QAAM,WAAW,aAAa,eAAe,SAAS;AACtD,QAAM,QAAQ,WAAW,OAAO;AAChC,QAAM,aAAa,SAAS,YAAY,IAAI;AAE5C,YAAU,MAAM;AACd,QAAI,UAAU,SAAS,SAAS;AAC9B,eAAS,UAAU;AACnB,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,YAAY,KAAK,CAAC;AAEtB,QAAM,SAAS,SAAS,CAAC,SAAS;AAChC,QAAI;AAAe;AACnB,YAAQ,IAAI,WAAW,UAAU,MAAM,IAAI;AAC3C,QAAI,UAAU;AACZ,YAAM,YAAY,OAAO,SAAS,aAAa,KAAK,SAAS,OAAO,IAAI;AACxE,iBAAW,SAAS;AAAA,IACtB,OAAO;AACL,eAAS,IAAI;AAAA,IACf;AAAA,EACF,CAAC;AAED,SAAO,CAAC,OAAY,MAAM;AAC5B;AAEA,MAAM,OAAO,MAAM;AAAC;",
6
- "names": []
7
- }