@pushwoosh/kit-helpers 4.16.0 → 4.16.2

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/expand.js CHANGED
@@ -1,4 +1,3 @@
1
- import { createElement as _createElement } from "react";
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import { useEffect, useRef, useState } from 'react';
4
3
  import { CSSTransition, TransitionGroup } from 'react-transition-group';
@@ -64,9 +63,9 @@ export const Collapse = ({
64
63
  ...rest
65
64
  }) => _jsx(TransitionGroup, {
66
65
  component: null,
67
- children: expanded && _createElement(CollapseTransition, {
66
+ children: expanded && _jsx(CollapseTransition, {
68
67
  ...rest,
69
68
  externalClassName: className,
70
- key: 0
71
- }, typeof children === 'function' ? children() : children)
69
+ children: typeof children === 'function' ? children() : children
70
+ }, 0)
72
71
  });
@@ -1,4 +1,4 @@
1
- import { useInsertionEffect, useRef } from 'react';
1
+ import { useInsertionEffect, useRef, useState } from 'react';
2
2
  /**
3
3
  * Creates a stable function reference that always calls the latest version of a callback.
4
4
  *
@@ -63,17 +63,10 @@ import { useInsertionEffect, useRef } from 'react';
63
63
  * };
64
64
  */
65
65
  export default function usePersistentFunction(callback) {
66
- const holderRef = useRef(null);
67
- if (holderRef.current === null) {
68
- const created = {
69
- latest: callback,
70
- fn: (...args) => created.latest(...args)
71
- };
72
- holderRef.current = created;
73
- }
74
- const holder = holderRef.current;
66
+ const latestRef = useRef(callback);
75
67
  useInsertionEffect(() => {
76
- holder.latest = callback;
68
+ latestRef.current = callback;
77
69
  });
78
- return holder.fn;
70
+ const [fn] = useState(() => (...args) => latestRef.current(...args));
71
+ return fn;
79
72
  }
@@ -1,10 +1,12 @@
1
- import { useRef } from 'react';
1
+ import { useLayoutEffect, useRef } from 'react';
2
2
  import useEffectOnce from './useEffectOnce';
3
3
  /** Call `fn` on unmount; the latest render's `fn` is used, so it needs no stable identity. */
4
4
  const useUnmount = fn => {
5
5
  const fnRef = useRef(fn);
6
6
  // update the ref each render so if it change the newest callback will be invoked
7
- fnRef.current = fn;
7
+ useLayoutEffect(() => {
8
+ fnRef.current = fn;
9
+ });
8
10
  useEffectOnce(() => () => fnRef.current());
9
11
  };
10
12
  export default useUnmount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.16.0",
3
+ "version": "4.16.2",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -14,7 +14,7 @@
14
14
  "react-transition-group": "^4.4.5"
15
15
  },
16
16
  "devDependencies": {
17
- "@pushwoosh/kit-constants": "^2.1.1",
17
+ "@pushwoosh/kit-constants": "^3.1.0",
18
18
  "@types/react": "^19.3.0",
19
19
  "@types/react-dom": "^19.3.0",
20
20
  "@types/react-transition-group": "^4.4.12",