@tamagui/use-controllable-state 1.0.0-canary.204 → 1.0.1-beta.100
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/useControllableState.js +8 -7
- package/dist/cjs/useControllableState.js.map +2 -2
- package/dist/esm/useControllableState.js +9 -9
- package/dist/esm/useControllableState.js.map +2 -2
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/useControllableState.js +9 -8
- package/dist/jsx/useControllableState.js.map +7 -0
- package/package.json +5 -4
- package/src/index.ts +1 -0
- package/src/useControllableState.ts +57 -0
- package/types/index.d.ts +0 -0
- package/types/useControllableState.d.ts +0 -0
- package/types/useControllableState.d.ts.map +1 -1
- package/LICENSE +0 -21
- package/types/index.d.ts.map +0 -1
|
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -35,28 +34,30 @@ function useControllableState({
|
|
|
35
34
|
const propWins = strategy === "prop-wins";
|
|
36
35
|
(0, import_react.useEffect)(() => {
|
|
37
36
|
currentProp.current = prop;
|
|
38
|
-
setVal((prev) =>
|
|
39
|
-
|
|
37
|
+
setVal((prev) => {
|
|
38
|
+
return getNextStateWithCallback(prev, prop, handleChange);
|
|
39
|
+
});
|
|
40
|
+
}, [handleChange, prop]);
|
|
40
41
|
return [
|
|
41
42
|
val,
|
|
42
43
|
(0, import_react.useCallback)((next) => {
|
|
43
44
|
if (propWins && currentProp.current !== void 0) {
|
|
45
|
+
handleChange(next);
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
48
|
setVal((prev) => {
|
|
47
49
|
return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, handleChange);
|
|
48
50
|
});
|
|
49
|
-
}, [
|
|
51
|
+
}, [propWins, handleChange])
|
|
50
52
|
];
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
const getNextStateWithCallback = /* @__PURE__ */ __name((prev, next, handleChange) => {
|
|
54
|
+
const getNextStateWithCallback = (prev, next, handleChange) => {
|
|
54
55
|
if (prev === next || next === void 0) {
|
|
55
56
|
return prev;
|
|
56
57
|
}
|
|
57
58
|
handleChange(next);
|
|
58
59
|
return next;
|
|
59
|
-
}
|
|
60
|
+
};
|
|
60
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
62
|
0 && (module.exports = {
|
|
62
63
|
useControllableState
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useControllableState.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallbackRef } from '@radix-ui/react-use-callback-ref'\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\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n strategy?: 'prop-wins' | 'most-recent-wins'\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const handleChange = useCallbackRef(onChange)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n useEffect(() => {\n currentProp.current = prop\n setVal((prev) => getNextStateWithCallback(prev, prop, handleChange))\n }, [prop])\n\n return [\n val,\n useCallback(\n (next:
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useCallbackRef } from '@radix-ui/react-use-callback-ref'\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\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n strategy?: 'prop-wins' | 'most-recent-wins'\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const handleChange = useCallbackRef(onChange)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n useEffect(() => {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, handleChange)\n })\n }, [handleChange, prop])\n\n return [\n val,\n useCallback(\n (next: unknown) => {\n if (propWins && currentProp.current !== undefined) {\n handleChange(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n handleChange\n )\n })\n },\n [propWins, handleChange]\n ),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange: any) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange(next)\n return next\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAA+B;AAC/B,mBAAgE;AAKzD,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,GAMoC;AAC/C,QAAM,cAAc,yBAAO,IAAI;AAC/B,QAAM,eAAe,kDAAe,QAAQ;AAC5C,QAAM,CAAC,KAAK,UAAU,2BAAS,QAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAE9B,8BAAU,MAAM;AACd,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,YAAY;AAAA,IAC1D,CAAC;AAAA,EACH,GAAG,CAAC,cAAc,IAAI,CAAC;AAEvB,SAAO;AAAA,IACL;AAAA,IACA,8BACE,CAAC,SAAkB;AACjB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,qBAAa,IAAS;AACtB;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,YACF;AAAA,MACF,CAAC;AAAA,IACH,GACA,CAAC,UAAU,YAAY,CACzB;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAsB;AAC5E,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,eAAa,IAAI;AACjB,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
4
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
3
|
function useControllableState({
|
|
@@ -10,32 +8,34 @@ function useControllableState({
|
|
|
10
8
|
}) {
|
|
11
9
|
const currentProp = useRef(prop);
|
|
12
10
|
const handleChange = useCallbackRef(onChange);
|
|
13
|
-
const [val, setVal] = useState(prop
|
|
11
|
+
const [val, setVal] = useState(prop ?? defaultProp);
|
|
14
12
|
const propWins = strategy === "prop-wins";
|
|
15
13
|
useEffect(() => {
|
|
16
14
|
currentProp.current = prop;
|
|
17
|
-
setVal((prev) =>
|
|
18
|
-
|
|
15
|
+
setVal((prev) => {
|
|
16
|
+
return getNextStateWithCallback(prev, prop, handleChange);
|
|
17
|
+
});
|
|
18
|
+
}, [handleChange, prop]);
|
|
19
19
|
return [
|
|
20
20
|
val,
|
|
21
21
|
useCallback((next) => {
|
|
22
22
|
if (propWins && currentProp.current !== void 0) {
|
|
23
|
+
handleChange(next);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
setVal((prev) => {
|
|
26
27
|
return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, handleChange);
|
|
27
28
|
});
|
|
28
|
-
}, [
|
|
29
|
+
}, [propWins, handleChange])
|
|
29
30
|
];
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
const getNextStateWithCallback = /* @__PURE__ */ __name((prev, next, handleChange) => {
|
|
32
|
+
const getNextStateWithCallback = (prev, next, handleChange) => {
|
|
33
33
|
if (prev === next || next === void 0) {
|
|
34
34
|
return prev;
|
|
35
35
|
}
|
|
36
36
|
handleChange(next);
|
|
37
37
|
return next;
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
export {
|
|
40
40
|
useControllableState
|
|
41
41
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useControllableState.ts"],
|
|
4
|
-
"sourcesContent": ["import { useCallbackRef } from '@radix-ui/react-use-callback-ref'\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\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n strategy?: 'prop-wins' | 'most-recent-wins'\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const handleChange = useCallbackRef(onChange)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n useEffect(() => {\n currentProp.current = prop\n setVal((prev) => getNextStateWithCallback(prev, prop, handleChange))\n }, [prop])\n\n return [\n val,\n useCallback(\n (next:
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useCallbackRef } from '@radix-ui/react-use-callback-ref'\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\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n strategy?: 'prop-wins' | 'most-recent-wins'\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const handleChange = useCallbackRef(onChange)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n useEffect(() => {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, handleChange)\n })\n }, [handleChange, prop])\n\n return [\n val,\n useCallback(\n (next: unknown) => {\n if (propWins && currentProp.current !== undefined) {\n handleChange(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n handleChange\n )\n })\n },\n [propWins, handleChange]\n ),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange: any) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange(next)\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AAKO,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,GAMoC;AAC/C,QAAM,cAAc,OAAO,IAAI;AAC/B,QAAM,eAAe,eAAe,QAAQ;AAC5C,QAAM,CAAC,KAAK,UAAU,SAAS,QAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAE9B,YAAU,MAAM;AACd,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,YAAY;AAAA,IAC1D,CAAC;AAAA,EACH,GAAG,CAAC,cAAc,IAAI,CAAC;AAEvB,SAAO;AAAA,IACL;AAAA,IACA,YACE,CAAC,SAAkB;AACjB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,qBAAa,IAAS;AACtB;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,YACF;AAAA,MACF,CAAC;AAAA,IACH,GACA,CAAC,UAAU,YAAY,CACzB;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAsB;AAC5E,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,eAAa,IAAI;AACjB,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
4
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
3
|
function useControllableState({
|
|
@@ -14,28 +12,31 @@ function useControllableState({
|
|
|
14
12
|
const propWins = strategy === "prop-wins";
|
|
15
13
|
useEffect(() => {
|
|
16
14
|
currentProp.current = prop;
|
|
17
|
-
setVal((prev) =>
|
|
18
|
-
|
|
15
|
+
setVal((prev) => {
|
|
16
|
+
return getNextStateWithCallback(prev, prop, handleChange);
|
|
17
|
+
});
|
|
18
|
+
}, [handleChange, prop]);
|
|
19
19
|
return [
|
|
20
20
|
val,
|
|
21
21
|
useCallback((next) => {
|
|
22
22
|
if (propWins && currentProp.current !== void 0) {
|
|
23
|
+
handleChange(next);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
setVal((prev) => {
|
|
26
27
|
return getNextStateWithCallback(prev, typeof next === "function" ? next(prev) : next, handleChange);
|
|
27
28
|
});
|
|
28
|
-
}, [
|
|
29
|
+
}, [propWins, handleChange])
|
|
29
30
|
];
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
const getNextStateWithCallback = /* @__PURE__ */ __name((prev, next, handleChange) => {
|
|
32
|
+
const getNextStateWithCallback = (prev, next, handleChange) => {
|
|
33
33
|
if (prev === next || next === void 0) {
|
|
34
34
|
return prev;
|
|
35
35
|
}
|
|
36
36
|
handleChange(next);
|
|
37
37
|
return next;
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
export {
|
|
40
40
|
useControllableState
|
|
41
41
|
};
|
|
42
|
+
//# sourceMappingURL=useControllableState.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useControllableState.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallbackRef } from '@radix-ui/react-use-callback-ref'\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\nexport function useControllableState<T>({\n prop,\n defaultProp,\n onChange,\n strategy = 'prop-wins',\n}: {\n prop?: T | undefined\n defaultProp: T\n onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>\n strategy?: 'prop-wins' | 'most-recent-wins'\n}): [T, React.Dispatch<React.SetStateAction<T>>] {\n const currentProp = useRef(prop)\n const handleChange = useCallbackRef(onChange)\n const [val, setVal] = useState(prop ?? defaultProp)\n const propWins = strategy === 'prop-wins'\n\n useEffect(() => {\n currentProp.current = prop\n setVal((prev) => {\n return getNextStateWithCallback(prev, prop, handleChange)\n })\n }, [handleChange, prop])\n\n return [\n val,\n useCallback(\n (next: unknown) => {\n if (propWins && currentProp.current !== undefined) {\n handleChange(next as T)\n return\n }\n setVal((prev) => {\n return getNextStateWithCallback(\n prev,\n typeof next === 'function' ? next(prev) : next,\n handleChange\n )\n })\n },\n [propWins, handleChange]\n ),\n ]\n}\n\nconst getNextStateWithCallback = (prev: any, next: any, handleChange: any) => {\n if (prev === next || next === undefined) {\n return prev\n }\n handleChange(next)\n return next\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AAKO,8BAAiC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,GAMoC;AAC/C,QAAM,cAAc,OAAO,IAAI;AAC/B,QAAM,eAAe,eAAe,QAAQ;AAC5C,QAAM,CAAC,KAAK,UAAU,SAAS,sBAAQ,WAAW;AAClD,QAAM,WAAW,aAAa;AAE9B,YAAU,MAAM;AACd,gBAAY,UAAU;AACtB,WAAO,CAAC,SAAS;AACf,aAAO,yBAAyB,MAAM,MAAM,YAAY;AAAA,IAC1D,CAAC;AAAA,EACH,GAAG,CAAC,cAAc,IAAI,CAAC;AAEvB,SAAO;AAAA,IACL;AAAA,IACA,YACE,CAAC,SAAkB;AACjB,UAAI,YAAY,YAAY,YAAY,QAAW;AACjD,qBAAa,IAAS;AACtB;AAAA,MACF;AACA,aAAO,CAAC,SAAS;AACf,eAAO,yBACL,MACA,OAAO,SAAS,aAAa,KAAK,IAAI,IAAI,MAC1C,YACF;AAAA,MACF,CAAC;AAAA,IACH,GACA,CAAC,UAAU,YAAY,CACzB;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,CAAC,MAAW,MAAW,iBAAsB;AAC5E,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO;AAAA,EACT;AACA,eAAa,IAAI;AACjB,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-controllable-state",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.100",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
|
-
"
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
7
|
"main": "dist/cjs",
|
|
8
8
|
"module": "dist/esm",
|
|
9
9
|
"module:jsx": "dist/jsx",
|
|
10
10
|
"files": [
|
|
11
|
+
"src",
|
|
11
12
|
"types",
|
|
12
13
|
"dist"
|
|
13
14
|
],
|
|
@@ -25,12 +26,12 @@
|
|
|
25
26
|
"react-dom": "*"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@tamagui/build": "^1.0.
|
|
29
|
+
"@tamagui/build": "^1.0.1-beta.100",
|
|
29
30
|
"react": "*",
|
|
30
31
|
"react-dom": "*"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
36
37
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useControllableState'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useCallbackRef } from '@radix-ui/react-use-callback-ref'
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
// can configure to allow most-recent-wins or prop-wins
|
|
5
|
+
// defaults to prop-wins
|
|
6
|
+
|
|
7
|
+
export function useControllableState<T>({
|
|
8
|
+
prop,
|
|
9
|
+
defaultProp,
|
|
10
|
+
onChange,
|
|
11
|
+
strategy = 'prop-wins',
|
|
12
|
+
}: {
|
|
13
|
+
prop?: T | undefined
|
|
14
|
+
defaultProp: T
|
|
15
|
+
onChange?: ((next: T) => void) | React.Dispatch<React.SetStateAction<T>>
|
|
16
|
+
strategy?: 'prop-wins' | 'most-recent-wins'
|
|
17
|
+
}): [T, React.Dispatch<React.SetStateAction<T>>] {
|
|
18
|
+
const currentProp = useRef(prop)
|
|
19
|
+
const handleChange = useCallbackRef(onChange)
|
|
20
|
+
const [val, setVal] = useState(prop ?? defaultProp)
|
|
21
|
+
const propWins = strategy === 'prop-wins'
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
currentProp.current = prop
|
|
25
|
+
setVal((prev) => {
|
|
26
|
+
return getNextStateWithCallback(prev, prop, handleChange)
|
|
27
|
+
})
|
|
28
|
+
}, [handleChange, prop])
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
val,
|
|
32
|
+
useCallback(
|
|
33
|
+
(next: unknown) => {
|
|
34
|
+
if (propWins && currentProp.current !== undefined) {
|
|
35
|
+
handleChange(next as T)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
setVal((prev) => {
|
|
39
|
+
return getNextStateWithCallback(
|
|
40
|
+
prev,
|
|
41
|
+
typeof next === 'function' ? next(prev) : next,
|
|
42
|
+
handleChange
|
|
43
|
+
)
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
[propWins, handleChange]
|
|
47
|
+
),
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getNextStateWithCallback = (prev: any, next: any, handleChange: any) => {
|
|
52
|
+
if (prev === next || next === undefined) {
|
|
53
|
+
return prev
|
|
54
|
+
}
|
|
55
|
+
handleChange(next)
|
|
56
|
+
return next
|
|
57
|
+
}
|
package/types/index.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../src/useControllableState.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAKvE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAsB,GACvB,EAAE;IACD,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,WAAW,EAAE,CAAC,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,QAAQ,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAA;CAC5C,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../src/useControllableState.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAKvE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EACtC,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAsB,GACvB,EAAE;IACD,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,WAAW,EAAE,CAAC,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,QAAQ,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAA;CAC5C,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAgC/C"}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Nate Wienert
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|