authscape 1.0.325 → 1.0.326
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/index.js +23 -13
- package/package.json +1 -1
- package/src/components/AutoSaveTextField.js +22 -12
package/index.js
CHANGED
|
@@ -150,21 +150,31 @@ function AutoSaveTextField(_ref) {
|
|
|
150
150
|
_useState2 = _slicedToArray(_useState, 2),
|
|
151
151
|
text = _useState2[0],
|
|
152
152
|
setText = _useState2[1];
|
|
153
|
+
var _useState3 = (0, _react.useState)(false),
|
|
154
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
155
|
+
isComponentMounted = _useState4[0],
|
|
156
|
+
setComponentMounted = _useState4[1];
|
|
153
157
|
(0, _react.useEffect)(function () {
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
// Set the componentMounted flag to true after the initial render
|
|
159
|
+
setComponentMounted(true);
|
|
160
|
+
}, []);
|
|
161
|
+
(0, _react.useEffect)(function () {
|
|
162
|
+
if (isComponentMounted) {
|
|
163
|
+
// Simulate saving text to a server or any storage mechanism
|
|
164
|
+
// In a real-world scenario, you would send a request to a server to save the text
|
|
165
|
+
// For this example, we'll just update the savedText state after 2 seconds
|
|
166
|
+
var saveTimeout = setTimeout(function () {
|
|
167
|
+
if (onChanged != null) {
|
|
168
|
+
onChanged(text);
|
|
169
|
+
}
|
|
170
|
+
}, timeout);
|
|
162
171
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
// Clean up the timeout to avoid unnecessary saves if the text changes again
|
|
173
|
+
return function () {
|
|
174
|
+
return clearTimeout(saveTimeout);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}, [text, isComponentMounted]);
|
|
168
178
|
var handleTextChange = function handleTextChange(event) {
|
|
169
179
|
var newText = event.target.value;
|
|
170
180
|
setText(newText);
|
package/package.json
CHANGED
|
@@ -3,21 +3,31 @@ import TextField from '@mui/material/TextField';
|
|
|
3
3
|
|
|
4
4
|
export function AutoSaveTextField ({label = "", variant = "outlined", timeout = 2000, isMultiLine = false, rows = 1, fullWidth = false, onChanged = null}) {
|
|
5
5
|
const [text, setText] = useState('');
|
|
6
|
+
const [isComponentMounted, setComponentMounted] = useState(false);
|
|
6
7
|
|
|
7
8
|
useEffect(() => {
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const saveTimeout = setTimeout(() => {
|
|
12
|
-
if (onChanged != null)
|
|
13
|
-
{
|
|
14
|
-
onChanged(text);
|
|
15
|
-
}
|
|
16
|
-
}, timeout);
|
|
9
|
+
// Set the componentMounted flag to true after the initial render
|
|
10
|
+
setComponentMounted(true);
|
|
11
|
+
}, []);
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
|
|
15
|
+
if (isComponentMounted)
|
|
16
|
+
{
|
|
17
|
+
// Simulate saving text to a server or any storage mechanism
|
|
18
|
+
// In a real-world scenario, you would send a request to a server to save the text
|
|
19
|
+
// For this example, we'll just update the savedText state after 2 seconds
|
|
20
|
+
const saveTimeout = setTimeout(() => {
|
|
21
|
+
if (onChanged != null)
|
|
22
|
+
{
|
|
23
|
+
onChanged(text);
|
|
24
|
+
}
|
|
25
|
+
}, timeout);
|
|
26
|
+
|
|
27
|
+
// Clean up the timeout to avoid unnecessary saves if the text changes again
|
|
28
|
+
return () => clearTimeout(saveTimeout);
|
|
29
|
+
}
|
|
30
|
+
}, [text, isComponentMounted]);
|
|
21
31
|
|
|
22
32
|
const handleTextChange = (event) => {
|
|
23
33
|
const newText = event.target.value;
|