import { useState } from "react"; /** * A hook that returns a promise and its state. * * The promise is only created once, and the state is updated when the promise resolves or rejects. * * @param factory A function that returns a promise. * @returns An object containing the promise's state and result. * @example * const { loading, result, error } = usePromise(() => fetch('https://example.com') * .then(response => response.text()) * ); * if (loading) { * return
Loading...
; * } * if (error) { * returnError: {error.message}
; * } * returnResult: {result}
; */ export function usePromise