Skip to content

Instantly share code, notes, and snippets.

@cameronp98
Last active May 24, 2020 17:34
Show Gist options
  • Save cameronp98/b224ccfb7677970cb409a24f2b8d48bb to your computer and use it in GitHub Desktop.
Save cameronp98/b224ccfb7677970cb409a24f2b8d48bb to your computer and use it in GitHub Desktop.
Semantic UI promise loader button
import React, { useState } from 'react'
import { Button } from 'semantic-ui-react'
// action returns a promise after the resolution of which `loading` is set to false
const PromiseButton = ({ action, children, ...props }) => {
const [loading, setLoading] = useState(false)
const handleClick = () => {
setLoading(true)
action().then(() => {
setLoading(false)
})
}
return (
<Button
{...props}
onClick={handleClick}
loading={loading}
disabled={loading}
>
{children}
</Button>
)
}
export default PromiseButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment