Skip to content

Instantly share code, notes, and snippets.

@tpjnorton
Created October 23, 2020 09:28
Show Gist options
  • Save tpjnorton/62fb6627ef52f0379bdade883c64a08d to your computer and use it in GitHub Desktop.
Save tpjnorton/62fb6627ef52f0379bdade883c64a08d to your computer and use it in GitHub Desktop.
const Button = ({onClick, ...rest}) => {
const [loading, setLoading] = useState(false);
const isMounted = useMounted();
const onClicked = async (e) => {
setLoading(true);
await onClick(e);
isMounted.current && setLoading(false);
}
return <button onClick={onClicked} {...rest}/>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment