Skip to content

Instantly share code, notes, and snippets.

@bullishgopher
Created October 24, 2020 11:50
Show Gist options
  • Save bullishgopher/ad794ab74bd2a30954fa1bdd833908d5 to your computer and use it in GitHub Desktop.
Save bullishgopher/ad794ab74bd2a30954fa1bdd833908d5 to your computer and use it in GitHub Desktop.
useDebounce
import React, { useState } from "react";
import { useDebounce } from "use-debounce";
export default function Input() {
const [text, setText] = useState("Hello");
const [value] = useDebounce(text, 1000);
return (
<div>
<input
defaultValue={"Hello"}
onChange={(e) => {
setText(e.target.value);
}}
/>
<p>Value: {text}</p>
<p>Debounced value: {value}</p>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment