I want to do a debounce for custom input, but my problem is I can't stop useEffect from trigger on initial render
import { useDebouncedCallback } from "use-debounce"; interface myInputProps { getValue: any; } const MyInput = ({ getValue }: myInputProps) => { const [value, setValue] = useState(""); React.useEffect(() => { getValue(value); }, [value]); return ( <input type="text" value={value} onChange={e => setValue(e.target.value)} /> ); }; export default function App() { const [debouncedCallback] = useDebouncedCallback(value => { console.log(value); }, 1000); return ( <div className="App"> <MyInput getValue={debouncedCallback} /> </div> ); } https://codesandbox.io/s/upbeat-lamport-ukq70?file=/src/App.tsx
I've also tried useLayoutEffect but it doesn't solve the problem.