Been using react material UI and want to use TextField that is both debounced (or throttled) and controlled.
controlled - the persistence value is held somewhere else and the component accepts the value and a onChange function as props.
debounced - the onChange function is called only when the user stops typing for a given amount of milliseconds. Of course for coherent display the component might hold an innerValue state.
I want the usage to be like this, with other props of TextField also relayed to the internal implementation
<TextFieldDebounced value={value} onChange={v => setValue(v)} debounceMs={500} />
Been looking for this for some time now and there are few webpages about the subject but couldn't create such a component.
Many thanks for all who answers.
You can achieve this by attaching a debounce function to a useCallback hook to prevent react from changing the debounced function's reference in subsequent re-renders.
This is the debounce function I use in multiple codebases
Here is a complete working sample on stackblitz