mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 22:14:50 +00:00
refactor(monorepo): decouple api and webui into workspaces packages
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import * as React from 'react'
|
||||
import { Input } from './input'
|
||||
|
||||
interface DebouncedInputProps extends Omit<
|
||||
React.ComponentProps<typeof Input>,
|
||||
'onChange' | 'value'
|
||||
> {
|
||||
value: string | number
|
||||
onChange: (value: string | number) => void
|
||||
debounce?: number
|
||||
}
|
||||
|
||||
export function DebouncedInput({
|
||||
value: initialValue,
|
||||
onChange,
|
||||
debounce = 500,
|
||||
...props
|
||||
}: DebouncedInputProps) {
|
||||
const [value, setValue] = React.useState(initialValue)
|
||||
|
||||
React.useEffect(() => {
|
||||
setValue(initialValue)
|
||||
}, [initialValue])
|
||||
|
||||
React.useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
if (value !== initialValue) {
|
||||
onChange(value)
|
||||
}
|
||||
}, debounce)
|
||||
|
||||
return () => clearTimeout(timeout)
|
||||
}, [value, debounce, onChange, initialValue])
|
||||
|
||||
return <Input {...props} value={value} onChange={(e) => setValue(e.target.value)} />
|
||||
}
|
||||
Reference in New Issue
Block a user