Function: holeFetchOptions()
holeFetchOptions(
spec):RequestInit&object
Defined in: holeFetchOptions.ts:29
Turns a hole's declared lifecycle into the fetch options Next reads, for a resolveHole
fetching the value that fills it.
Parameters
spec
FieldHintData
The hole's FieldHintData, as compile copied it from the block's ui.fields
hint into the artifact node's holes. Pass it through rather than choosing an interval at
the call site: the published artifact is what says how live the value is.
Returns
RequestInit & object
{ next: { revalidate: spec.revalidate } }, ready to spread into a fetch call.
0 reaches Next as 0 rather than being read as absent, which is Next's instruction not to
cache the response at all.
Example
import type { HoleResolver } from "@nubbin/react";
const resolveHole: HoleResolver = async ({ spec }) => {
const response = await fetch(`${origin}/api/price`, holeFetchOptions(spec));
return response.json();
};