@spark-ui/use-combined-state 0.3.0 → 0.4.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,16 @@
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.4.0](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.3.1...@spark-ui/use-combined-state@0.4.0) (2023-04-19)
7
+
8
+ ### Features
9
+
10
+ - **switch:** customisable icons for switch, controlled mode ([543568e](https://github.com/adevinta/spark/commit/543568e5c5eedc9a6e2ea6a0ef669c73f4b1ce12))
11
+
12
+ ## [0.3.1](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.3.0...@spark-ui/use-combined-state@0.3.1) (2023-04-13)
13
+
14
+ **Note:** Version bump only for package @spark-ui/use-combined-state
15
+
6
16
  # [0.3.0](https://github.com/adevinta/spark/compare/@spark-ui/use-combined-state@0.2.0...@spark-ui/use-combined-state@0.3.0) (2023-04-07)
7
17
 
8
18
  ### Features
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@spark-ui/use-mounted-state"),f=require("lodash.isequal"),u=require("react");exports.useCombinedState=function(e,c){const{current:r}=u.useRef(e===void 0?c:e),[i,t]=u.useState(r),n=d.useMountedState();u.useLayoutEffect(()=>{n()&&t(e)},[e,t,n]);const a=u.useCallback((s,o)=>{(e===void 0||o)&&!f(s,i)&&t(s)},[e,t]);return[i,a,e!==void 0,r]};
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]};
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import { useMountedState as c } from "@spark-ui/use-mounted-state";
2
- import f from "lodash.isequal";
3
- import { useRef as d, useState as p, useLayoutEffect as n, useCallback as v } from "react";
4
- function C(t, u) {
5
- const { current: o } = d(t === void 0 ? u : t), [s, e] = p(o), a = c();
6
- n(() => {
7
- a() && e(t);
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
8
  }, [t, e, a]);
9
- const i = v((r, m) => {
10
- (t === void 0 || m) && !f(r, s) && e(r);
11
- }, [t, e]);
12
- return [s, i, t !== void 0, o];
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];
13
13
  }
14
14
  export {
15
15
  C as useCombinedState
@@ -1 +1,5 @@
1
- export declare function useCombinedState(controlledValue?: any, defaultValue?: any): [any, (newValue: any, forceFlag?: boolean) => any, boolean, any];
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.
4
+ */
5
+ export declare function useCombinedState<T>(controlledValue?: T, defaultValue?: T): [T | undefined, (newValue: T, forceFlag?: boolean) => void, boolean, T | undefined];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/use-combined-state",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "combine controlled-uncontrolled component state by stateful-stateless inner state management",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,5 +25,5 @@
25
25
  "react": "^16.8 || ^17.0 || ^18.0",
26
26
  "react-dom": "^16.8 || ^17.0 || ^18.0"
27
27
  },
28
- "gitHead": "a5e5af21496ded1cce43912266002fa36b3ac328"
28
+ "gitHead": "f1070e260587a4ea0e3c0f6c83fe38a698ef8fd8"
29
29
  }