MCPcopy Create free account
hub / github.com/TanStack/query / Button

Function Button

examples/solid/suspense/src/components/Button.tsx:5–29  ·  view source on GitHub ↗
(props: {
  children: JSX.Element
  onClick: () => void
})

Source from the content-addressed store, hash-verified

3import type { JSX } from 'solid-js'
4
5export 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}

Callers

nothing calls this directly

Calls 1

isLoadingFunction · 0.85

Tested by

no test coverage detected