react-simplikit 0.0.15 → 0.0.16

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.
@@ -31,14 +31,14 @@ function usePrevious(state, compare = strictEquals) {
31
31
  const prevRef = (0, import_react.useRef)(state);
32
32
  const currentRef = (0, import_react.useRef)(state);
33
33
  const isFirstRender = (0, import_react.useRef)(true);
34
- (0, import_react.useEffect)(() => {
34
+ if (isFirstRender.current) {
35
35
  isFirstRender.current = false;
36
- }, []);
37
- if (isFirstRender.current || compare(currentRef.current, state)) {
38
36
  return prevRef.current;
39
37
  }
40
- prevRef.current = currentRef.current;
41
- currentRef.current = state;
38
+ if (!compare(currentRef.current, state)) {
39
+ prevRef.current = currentRef.current;
40
+ currentRef.current = state;
41
+ }
42
42
  return prevRef.current;
43
43
  }
44
44
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.cjs CHANGED
@@ -519,14 +519,14 @@ function usePrevious(state, compare = strictEquals) {
519
519
  const prevRef = (0, import_react18.useRef)(state);
520
520
  const currentRef = (0, import_react18.useRef)(state);
521
521
  const isFirstRender = (0, import_react18.useRef)(true);
522
- (0, import_react18.useEffect)(() => {
522
+ if (isFirstRender.current) {
523
523
  isFirstRender.current = false;
524
- }, []);
525
- if (isFirstRender.current || compare(currentRef.current, state)) {
526
524
  return prevRef.current;
527
525
  }
528
- prevRef.current = currentRef.current;
529
- currentRef.current = state;
526
+ if (!compare(currentRef.current, state)) {
527
+ prevRef.current = currentRef.current;
528
+ currentRef.current = state;
529
+ }
530
530
  return prevRef.current;
531
531
  }
532
532
 
@@ -1,18 +1,18 @@
1
1
  // src/hooks/usePrevious/usePrevious.ts
2
- import { useEffect, useRef } from "react";
2
+ import { useRef } from "react";
3
3
  var strictEquals = (prev, next) => prev === next;
4
4
  function usePrevious(state, compare = strictEquals) {
5
5
  const prevRef = useRef(state);
6
6
  const currentRef = useRef(state);
7
7
  const isFirstRender = useRef(true);
8
- useEffect(() => {
8
+ if (isFirstRender.current) {
9
9
  isFirstRender.current = false;
10
- }, []);
11
- if (isFirstRender.current || compare(currentRef.current, state)) {
12
10
  return prevRef.current;
13
11
  }
14
- prevRef.current = currentRef.current;
15
- currentRef.current = state;
12
+ if (!compare(currentRef.current, state)) {
13
+ prevRef.current = currentRef.current;
14
+ currentRef.current = state;
15
+ }
16
16
  return prevRef.current;
17
17
  }
18
18
  export {
package/esm/index.js CHANGED
@@ -464,20 +464,20 @@ function areDeeplyEqual(x, y) {
464
464
  }
465
465
 
466
466
  // src/hooks/usePrevious/usePrevious.ts
467
- import { useEffect as useEffect10, useRef as useRef9 } from "react";
467
+ import { useRef as useRef9 } from "react";
468
468
  var strictEquals = (prev, next) => prev === next;
469
469
  function usePrevious(state, compare = strictEquals) {
470
470
  const prevRef = useRef9(state);
471
471
  const currentRef = useRef9(state);
472
472
  const isFirstRender = useRef9(true);
473
- useEffect10(() => {
473
+ if (isFirstRender.current) {
474
474
  isFirstRender.current = false;
475
- }, []);
476
- if (isFirstRender.current || compare(currentRef.current, state)) {
477
475
  return prevRef.current;
478
476
  }
479
- prevRef.current = currentRef.current;
480
- currentRef.current = state;
477
+ if (!compare(currentRef.current, state)) {
478
+ prevRef.current = currentRef.current;
479
+ currentRef.current = state;
480
+ }
481
481
  return prevRef.current;
482
482
  }
483
483
 
@@ -621,7 +621,7 @@ function useStorageState(key, { storage = safeLocalStorage, defaultValue } = {})
621
621
  }
622
622
 
623
623
  // src/hooks/useThrottle/useThrottle.ts
624
- import { useEffect as useEffect11, useMemo as useMemo6 } from "react";
624
+ import { useEffect as useEffect10, useMemo as useMemo6 } from "react";
625
625
 
626
626
  // src/hooks/useThrottle/throttle.ts
627
627
  function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
@@ -651,7 +651,7 @@ function useThrottle(callback, wait, options) {
651
651
  () => throttle(preservedCallback, wait, preservedOptions),
652
652
  [preservedOptions, preservedCallback, wait]
653
653
  );
654
- useEffect11(() => {
654
+ useEffect10(() => {
655
655
  return () => {
656
656
  throttledCallback.cancel();
657
657
  };
@@ -660,10 +660,10 @@ function useThrottle(callback, wait, options) {
660
660
  }
661
661
 
662
662
  // src/hooks/useTimeout/useTimeout.ts
663
- import { useEffect as useEffect12 } from "react";
663
+ import { useEffect as useEffect11 } from "react";
664
664
  function useTimeout(callback, delay = 0) {
665
665
  const preservedCallback = usePreservedCallback(callback);
666
- useEffect12(() => {
666
+ useEffect11(() => {
667
667
  const timeoutId = window.setTimeout(preservedCallback, delay);
668
668
  return () => window.clearTimeout(timeoutId);
669
669
  }, [delay, preservedCallback]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simplikit",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "sideEffects": false,