deno.land / x / ultra@v2.3.8 / hooks / use-asset.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { useContext, useMemo } from "react";import AssetContext from "./asset-context.js";
/** * This hook returns the resolved path from the generated `asset-manifest.json` * It has no effect during development. * * @param {string} [path] */export default function useAsset(path) { if (path === undefined) { throw new Error("a path must be supplied"); }
if (path.startsWith("/") === false) { throw new Error( `The path provided to the useAsset hook must begin with "/" received: ${path}`, ); }
const context = useContext(AssetContext) || new Map(globalThis.__ULTRA_ASSET_MAP || []);
return useMemo(() => context.get(path) || path, [path]);}
ultra

Version Info

Tagged at
8 months ago