usePromise
hookas/use-promiseFreeHook
A hook to handle promises
Install it
npx shadcn@latest add https://hookas.letstri.dev/r/use-promise.jsonSource
1'use client'23import * as React from 'react'4import { useIsomorphicEffect } from './use-isomorphic-effect'56export function usePromise<T>(promiseFn: () => Promise<T>): T | undefined7export function usePromise<T, D>(promiseFn: () => Promise<T>, initialData: D): T | D8export function usePromise<T, D>(9 promiseFn: () => Promise<T>,10 initialData?: D,11) {12 const [data, setData] = React.useState<T | D | undefined>(initialData)1314 useIsomorphicEffect(() => {15 promiseFn().then(setData)16 }, [])1718 return data19}
What it pulls in
Other registry items
Files it writes
More from hookas
All 30 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| useAsyncEffectuse-async-effect | hookas | Hooks | Free | no deps | |
| useClickOutsideuse-click-outside | hookas | Hooks | Free | no deps | |
| useDebounceCallbackuse-debounced-callback | hookas | Hooks | Free | no deps | |
| useDebounceMemouse-debounced-memo | hookas | Hooks | Free | no deps | |
| useDebounceStateuse-debounced-state | hookas | Hooks | Free | no deps | |
| useElementSizeuse-element-size | hookas | Hooks | Free | no deps | |
| useFullscreenuse-fullscreen | hookas | Hooks | Free | no deps | |
| useIntervaluse-interval | hookas | Hooks | Free | no deps |
