import { Accessor, AnyReactive } from "../utils"; import { ResourceActions, ResourceOptions, ResourceState } from "./resource"; export type CreateResourceReturn = [ResourceState, ResourceActions]; /** * Creates a resource that wraps a repeated promise in a reactive pattern: * ```typescript * // Without source * const [resource, { mutate, refetch }] = createResource({ * fetcher: () => fetch("https://swapi.dev/api/people/1").then((r) => r.json()), * }); * // With source * const [resource, { mutate, refetch }] = createResource({ * source: () => userId.value, * fetcher: (userId) => fetch(`https://swapi.dev/api/people/${userId}`).then((r) => r.json()), * }); * ``` * @param options - Contains all options for creating resource * * @returns ```typescript * [ResourceState, { mutate: Setter, refetch: () => void }] * ``` * * * Setting an `initialValue` in the options will mean that resource will be created in `ready` state * * `mutate` allows to manually overwrite the resource without calling the fetcher * * `refetch` will re-run the fetcher without changing the source, and if called with a value, that value will be passed to the fetcher via the `refetching` property on the fetcher's second parameter * */ export declare function createResource, TRefreshing = boolean>(options: ResourceOptions): CreateResourceReturn;