Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

Button.jsx

21 lines424 Bytes

1import React from 'react'
2​
3import Spinner from './Spinner'
4​
5export default function Button({ children, onClick }) {
6 const [isPending, startTransition] = React.useTransition()
7​
8 const handleClick = (e) => {
9 startTransition(() => {
10 onClick(e)
11 })
12 }
13​
14 return (
15 <>
16 <button onClick={handleClick} disabled={isPending}>
17 {children} {isPending ? <Spinner /> : null}
18 </button>
19 </>
20 )