[example][m] - start of a simple-example

This commit is contained in:
Luccas Mateus de Medeiros Gomes
2023-04-18 08:19:58 -03:00
parent 34cbb1e8af
commit 751093baf6
43 changed files with 6837 additions and 238 deletions

View File

@@ -0,0 +1,33 @@
import { useEffect, useState } from "react";
const DebouncedInput = ({
value: initialValue,
onChange,
debounce = 500,
...props
}) => {
const [value, setValue] = useState(initialValue);
useEffect(() => {
setValue(initialValue);
}, [initialValue]);
useEffect(() => {
const timeout = setTimeout(() => {
onChange(value);
}, debounce);
return () => clearTimeout(timeout);
}, [value]);
return (
<input
{...props}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
};
export default DebouncedInput;