forked from pavlitoPogosov/React-Table-Component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHeadInput.tsx
More file actions
26 lines (19 loc) · 848 Bytes
/
Copy pathTableHeadInput.tsx
File metadata and controls
26 lines (19 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import React, {type ChangeEvent, useState, useEffect} from 'react';
import {useDebouncedCallback} from 'use-debounce';
import type {TableHeadInputProps} from './types';
import {NewInput} from '../NewInput';
export {type TableHeadInputProps};
export function TableHeadInput({debounceInterval = 600, value = '', onChange, ...props}: TableHeadInputProps) {
const [inputValue, setInputValue] = useState(value);
const onChangeDebounced = useDebouncedCallback((debounced: string) => {
onChange?.(debounced);
}, debounceInterval);
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
onChangeDebounced(e.target.value);
setInputValue(e.target.value);
};
useEffect(() => {
setInputValue(value);
}, [value]);
return <NewInput size="s" value={inputValue} variant="table" onChange={handleChange} {...props} />;
}