Created
October 24, 2020 11:50
-
-
Save xgracias/ad794ab74bd2a30954fa1bdd833908d5 to your computer and use it in GitHub Desktop.
useDebounce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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