react-simplikit 0.0.14 → 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:
@@ -131,9 +131,10 @@ function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
131
131
  function useThrottle(callback, wait, options) {
132
132
  const preservedCallback = usePreservedCallback(callback);
133
133
  const preservedOptions = usePreservedReference(options ?? {});
134
- const throttledCallback = (0, import_react3.useMemo)(() => {
135
- return throttle(preservedCallback, wait, preservedOptions);
136
- }, [preservedOptions, preservedCallback, wait]);
134
+ const throttledCallback = (0, import_react3.useMemo)(
135
+ () => throttle(preservedCallback, wait, preservedOptions),
136
+ [preservedOptions, preservedCallback, wait]
137
+ );
137
138
  (0, import_react3.useEffect)(() => {
138
139
  return () => {
139
140
  throttledCallback.cancel();
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
 
@@ -696,9 +696,10 @@ function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
696
696
  function useThrottle(callback, wait, options) {
697
697
  const preservedCallback = usePreservedCallback(callback);
698
698
  const preservedOptions = usePreservedReference(options ?? {});
699
- const throttledCallback = (0, import_react20.useMemo)(() => {
700
- return throttle(preservedCallback, wait, preservedOptions);
701
- }, [preservedOptions, preservedCallback, wait]);
699
+ const throttledCallback = (0, import_react20.useMemo)(
700
+ () => throttle(preservedCallback, wait, preservedOptions),
701
+ [preservedOptions, preservedCallback, wait]
702
+ );
702
703
  (0, import_react20.useEffect)(() => {
703
704
  return () => {
704
705
  throttledCallback.cancel();
@@ -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 {
@@ -105,9 +105,10 @@ function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
105
105
  function useThrottle(callback, wait, options) {
106
106
  const preservedCallback = usePreservedCallback(callback);
107
107
  const preservedOptions = usePreservedReference(options ?? {});
108
- const throttledCallback = useMemo2(() => {
109
- return throttle(preservedCallback, wait, preservedOptions);
110
- }, [preservedOptions, preservedCallback, wait]);
108
+ const throttledCallback = useMemo2(
109
+ () => throttle(preservedCallback, wait, preservedOptions),
110
+ [preservedOptions, preservedCallback, wait]
111
+ );
111
112
  useEffect2(() => {
112
113
  return () => {
113
114
  throttledCallback.cancel();
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"] } = {}) {
@@ -647,10 +647,11 @@ function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
647
647
  function useThrottle(callback, wait, options) {
648
648
  const preservedCallback = usePreservedCallback(callback);
649
649
  const preservedOptions = usePreservedReference(options ?? {});
650
- const throttledCallback = useMemo6(() => {
651
- return throttle(preservedCallback, wait, preservedOptions);
652
- }, [preservedOptions, preservedCallback, wait]);
653
- useEffect11(() => {
650
+ const throttledCallback = useMemo6(
651
+ () => throttle(preservedCallback, wait, preservedOptions),
652
+ [preservedOptions, preservedCallback, wait]
653
+ );
654
+ useEffect10(() => {
654
655
  return () => {
655
656
  throttledCallback.cancel();
656
657
  };
@@ -659,10 +660,10 @@ function useThrottle(callback, wait, options) {
659
660
  }
660
661
 
661
662
  // src/hooks/useTimeout/useTimeout.ts
662
- import { useEffect as useEffect12 } from "react";
663
+ import { useEffect as useEffect11 } from "react";
663
664
  function useTimeout(callback, delay = 0) {
664
665
  const preservedCallback = usePreservedCallback(callback);
665
- useEffect12(() => {
666
+ useEffect11(() => {
666
667
  const timeoutId = window.setTimeout(preservedCallback, delay);
667
668
  return () => window.clearTimeout(timeoutId);
668
669
  }, [delay, preservedCallback]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-simplikit",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "sideEffects": false,