Last active
September 5, 2022 09:25
-
-
Save StokeMasterJack/a5e8773215919b292250744977ac3ed5 to your computer and use it in GitHub Desktop.
Prevent Double-Click Dups in React
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
function App() { | |
const onClick = () => console.log("onClick"); | |
return <button onClick={onClick}>Click Me</button>; | |
} |
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
function App() { | |
const onClick = () => console.log("onClick"); | |
const onClick2 = debounce(onClick, 300) | |
return <button onClick={onClick2}>Click Me</button>; | |
} |
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
function App() { | |
const [count, setCount] = useState(0); | |
const onClick = () => setCount(prev => prev + 1); | |
const onClick2 = debounce(onClick, 300); | |
return <div> | |
Count: {count} | |
<br/> | |
<button onClick={onClick2}>Click Me</button> | |
</div> | |
} |
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
function App() { | |
const [count, setCount] = useState(0); | |
const onClick = () => setCount(prev => prev + 1); | |
const onClick2 = debounce(onClick, 300); | |
const onClick3 = useCallback(onClick2, []); | |
return <div>Count: {count} | |
<br/> | |
<button onClick={onClick3}>Click Me</button> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the difference