(props: {
children: JSX.Element
onClick: () => void
})
| 3 | import type { JSX } from 'solid-js' |
| 4 | |
| 5 | export default function Button(props: { |
| 6 | children: JSX.Element |
| 7 | onClick: () => void |
| 8 | }) { |
| 9 | const [isPending, startTransition] = useTransition() |
| 10 | const [isStarted, setIsStarted] = createSignal(false) |
| 11 | const isLoading = () => isStarted() && isPending() |
| 12 | |
| 13 | return ( |
| 14 | <button |
| 15 | onClick={() => { |
| 16 | setIsStarted(true) |
| 17 | void startTransition(() => { |
| 18 | props.onClick() |
| 19 | }).then(() => setIsStarted(false)) |
| 20 | }} |
| 21 | disabled={isLoading()} |
| 22 | > |
| 23 | {props.children}{' '} |
| 24 | <Show when={isLoading()}> |
| 25 | <Spinner /> |
| 26 | </Show> |
| 27 | </button> |
| 28 | ) |
| 29 | } |
nothing calls this directly
no test coverage detected