@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 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 l=require("@spark-ui/use-mounted-state"),o=require("lodash.isequal"),u=require("react");exports.useCombinedState=function(e,c){const{current:n}=u.useRef(e===void 0?c:e),[r,t]=u.useState(n),i=l.useMountedState();u.useLayoutEffect(()=>{i()&&e!=null&&t(e)},[e,t,i]);const a=u.useCallback((s,d)=>{(e===void 0||d)&&!o(s,r)&&t(s)},[e,t,r]);return[r,a,e!==void 0,n]};
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 { useMountedState as f } from "@spark-ui/use-mounted-state";
2
- import m from "lodash.isequal";
3
- import { useRef as d, useState as u, useLayoutEffect as p, useCallback as l } from "react";
4
- function C(t, n) {
5
- const { current: s } = d(t === void 0 ? n : t), [o, e] = u(s), a = f();
6
- p(() => {
7
- a() && t != null && e(t);
8
- }, [t, e, a]);
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
- C as useCombinedState
11
+ v as useCombinedState
16
12
  };
@@ -1,5 +1,10 @@
1
1
  /**
2
- * This hook must be used when a component have both a controlled and uncontrolled mode.
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): [T | undefined, (newValue: T, forceFlag?: boolean) => void, boolean, T | undefined];
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.4.4",
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": "f83534112dc0eaf1fea3b747e5570fff39397b96"
33
+ "gitHead": "0aaa97e8a8e12cec11657e09953fb119b39ba6d3"
34
34
  }