@pushwoosh/kit-helpers 4.5.0 → 4.6.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.
@@ -22,5 +22,8 @@ export type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturning
22
22
  StateFromFunctionReturningPromise<T>,
23
23
  T
24
24
  ];
25
+ export type CallbackParams = {
26
+ reset?: boolean;
27
+ };
25
28
  export default function useAsyncFn<T extends FunctionReturningPromise>(fn: T, deps?: DependencyList, initialState?: StateFromFunctionReturningPromise<T> | (() => StateFromFunctionReturningPromise<T>)): AsyncFnReturn<T>;
26
29
  export {};
@@ -7,17 +7,21 @@ export default function useAsyncFn(fn, deps = [], initialState = getDefaultState
7
7
  const lastCallId = useRef(0);
8
8
  const isMounted = useMountedState();
9
9
  const [state, setState] = useState(initialState);
10
- const callback = useCallback((...args) => {
10
+ const callback = useCallback(({
11
+ reset
12
+ } = {}) => {
11
13
  // eslint-disable-next-line no-plusplus
12
14
  const callId = ++lastCallId.current;
13
15
  const canSet = () => isMounted() && callId === lastCallId.current;
14
16
  if (canSet()) {
15
- setState(prevState => ({
17
+ setState(prevState => reset ? {
18
+ loading: true
19
+ } : {
16
20
  ...prevState,
17
21
  loading: true
18
- }));
22
+ });
19
23
  }
20
- return fn(...args).then(value => {
24
+ return fn().then(value => {
21
25
  if (canSet()) {
22
26
  setState({
23
27
  value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",