@spark-ui/use-combined-state 0.4.4 → 0.5.0
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/CHANGELOG.md +11 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +9 -13
- package/dist/useCombinedState.d.ts +8 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.5.0](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.4.5...@spark-ui/use-combined-state@0.5.0) (2023-06-09)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **use-combined-state:** add onChange handler argument ([f546bf7](https://github.com/adevinta/spark/commit/f546bf7625664accb37f1f43e98202d1d39fca15))
|
|
11
|
+
- **use-combined-state:** remove unnecessary state management when controlled state mode ([95f45ba](https://github.com/adevinta/spark/commit/95f45ba467cebaef2c8d6ad42081aed0720e3fe7))
|
|
12
|
+
|
|
13
|
+
## [0.4.5](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.4.4...@spark-ui/use-combined-state@0.4.5) (2023-06-01)
|
|
14
|
+
|
|
15
|
+
**Note:** Version bump only for package @spark-ui/use-combined-state
|
|
16
|
+
|
|
6
17
|
## [0.4.4](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.4.3...@spark-ui/use-combined-state@0.4.4) (2023-05-10)
|
|
7
18
|
|
|
8
19
|
### Bug Fixes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("lodash.isequal"),c=require("react");exports.useCombinedState=function(r,i,o){const e=r!==void 0,{current:s}=c.useRef(e?r:i),[a,l]=c.useState(i),n=e?r:a,f=c.useCallback((u,b=(t,d)=>!S(t,d))=>{const t=typeof u!="function"?u:u(n);b(n,t)&&!e&&l(t),o&&o(t)},[e,n]);return[n,f,e,s]};
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const i = l((r, c) => {
|
|
10
|
-
(t === void 0 || c) && !m(r, o) && e(r);
|
|
11
|
-
}, [t, e, o]);
|
|
12
|
-
return [o, i, t !== void 0, s];
|
|
1
|
+
import b from "lodash.isequal";
|
|
2
|
+
import { useRef as d, useState as l, useCallback as C } from "react";
|
|
3
|
+
function v(n, r, a) {
|
|
4
|
+
const o = n !== void 0, { current: u } = d(o ? n : r), [f, m] = l(r), e = o ? n : f, c = C((s, i = (t, p) => !b(t, p)) => {
|
|
5
|
+
const t = typeof s != "function" ? s : s(e);
|
|
6
|
+
i(e, t) && !o && m(t), a && a(t);
|
|
7
|
+
}, [o, e]);
|
|
8
|
+
return [e, c, o, u];
|
|
13
9
|
}
|
|
14
10
|
export {
|
|
15
|
-
|
|
11
|
+
v as useCombinedState
|
|
16
12
|
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This hook must be used when a component
|
|
3
|
-
* It will take care of updating the state value when controlled mode (prop) is updated.
|
|
2
|
+
* This hook must be used when a component has both a controlled and uncontrolled mode.
|
|
3
|
+
* It will take care of updating the state value when a controlled mode (prop) is updated.
|
|
4
4
|
*/
|
|
5
|
-
export declare function useCombinedState<T>(controlledValue?: T, defaultValue?: T
|
|
5
|
+
export declare function useCombinedState<T>(controlledValue?: T, defaultValue?: T, onChange?: (nextValue: T) => void): [
|
|
6
|
+
T | undefined,
|
|
7
|
+
(newValue: T, forceFlag?: (prev: T, next: T) => boolean) => void,
|
|
8
|
+
boolean,
|
|
9
|
+
T | undefined
|
|
10
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/use-combined-state",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "combine controlled-uncontrolled component state by stateful-stateless inner state management",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://sparkui.vercel.app",
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "0aaa97e8a8e12cec11657e09953fb119b39ba6d3"
|
|
34
34
|
}
|