@etsoo/react 1.2.80 → 1.2.81

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.
@@ -17,6 +17,7 @@ export const CountdownButton = React.forwardRef((props, ref) => {
17
17
  const seconds = 2;
18
18
  // Countdown length
19
19
  const [shared] = React.useState({ maxLength: 0 });
20
+ const isMounted = React.useRef(true);
20
21
  // endIcon
21
22
  let endIcon;
22
23
  if (state === 0) {
@@ -43,6 +44,9 @@ export const CountdownButton = React.forwardRef((props, ref) => {
43
44
  // Update max length
44
45
  shared.maxLength = result.toString().length;
45
46
  const seed = setInterval(() => {
47
+ // Mounted?
48
+ if (!isMounted.current)
49
+ return;
46
50
  // Last 1 second and then complete
47
51
  if (result > seconds + 1) {
48
52
  result--;
@@ -68,5 +72,10 @@ export const CountdownButton = React.forwardRef((props, ref) => {
68
72
  // Return any countdown
69
73
  onAction().then(doAction);
70
74
  };
75
+ React.useEffect(() => {
76
+ return () => {
77
+ isMounted.current = false;
78
+ };
79
+ }, []);
71
80
  return (React.createElement(Button, { disabled: disabled, endIcon: endIcon, onClick: localClick, ref: ref, ...rest }));
72
81
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.2.80",
3
+ "version": "1.2.81",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -42,6 +42,8 @@ export const CountdownButton = React.forwardRef<
42
42
  // Countdown length
43
43
  const [shared] = React.useState({ maxLength: 0 });
44
44
 
45
+ const isMounted = React.useRef(true);
46
+
45
47
  // endIcon
46
48
  let endIcon: React.ReactNode;
47
49
  if (state === 0) {
@@ -70,6 +72,9 @@ export const CountdownButton = React.forwardRef<
70
72
  shared.maxLength = result.toString().length;
71
73
 
72
74
  const seed = setInterval(() => {
75
+ // Mounted?
76
+ if (!isMounted.current) return;
77
+
73
78
  // Last 1 second and then complete
74
79
  if (result > seconds + 1) {
75
80
  result--;
@@ -96,6 +101,12 @@ export const CountdownButton = React.forwardRef<
96
101
  onAction().then(doAction);
97
102
  };
98
103
 
104
+ React.useEffect(() => {
105
+ return () => {
106
+ isMounted.current = false;
107
+ };
108
+ }, []);
109
+
99
110
  return (
100
111
  <Button
101
112
  disabled={disabled}