Spaces:
Sleeping
Sleeping
Download src/lib/useDynamicConfig.ts from network01/ai-comic-factory: direct link, hf CLI and curl.
- Browser
- Download file 809 Bytes
-
https://huggingface.co/spaces/network01/ai-comic-factory/resolve/main/src/lib/useDynamicConfig.ts
- Command line
-
hf download hf://spaces/network01/ai-comic-factory/src/lib/useDynamicConfig.ts
-
curl -L -o useDynamicConfig.ts https://huggingface.co/spaces/network01/ai-comic-factory/resolve/main/src/lib/useDynamicConfig.ts
809 Bytes
| "use client" | |
| import { useEffect, useState, useTransition } from "react" | |
| import { getDynamicConfig } from "@/app/queries/getDynamicConfig" | |
| import { DynamicConfig } from "@/types" | |
| import { getDefaultDynamicConfig } from "./getDefaultDynamicConfig" | |
| export function useDynamicConfig(): { | |
| config: DynamicConfig; | |
| isConfigReady: boolean; | |
| } { | |
| const [_isPending, startTransition] = useTransition() | |
| const [config, setConfig] = useState<DynamicConfig>(getDefaultDynamicConfig()) | |
| const [isConfigReady, setConfigReady] = useState(false) | |
| useEffect(() => { | |
| startTransition(async () => { | |
| if (isConfigReady) { return } | |
| const newConfig = await getDynamicConfig() | |
| setConfig(newConfig) | |
| setConfigReady(true) | |
| }) | |
| }, [isConfigReady]) | |
| return { | |
| config, | |
| isConfigReady | |
| } | |
| } | |