BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/guarahooks/use-ky

UseKy

guarahooks/use-ky
FreeHook

A customizable hook for making HTTP requests using Ky

Install it

npx shadcn@latest add https://guarahooks.com/r/use-ky.json

Source

registry/hooks/use-ky.tsxguarahooks.com/r/use-ky.json · first 6 KB
1'use client';
2
3import {
4 createContext,
5 useCallback,
6 useContext,
7 useEffect,
8 useRef,
9 useState,
10 type ReactNode,
11} from 'react';
12
13import ky, {
14 HTTPError,
15 KyInstance,
16 KyResponse,
17 Options,
18 TimeoutError,
19} from 'ky';
20
21// #region Types & Interfaces
22
23export interface KyPlugin {
24 beforeRequest?: (url: string, options: Options) => void | Promise<void>;
25 afterResponse?: (response: KyResponse) => void | Promise<void>;
26 onError?: (error: HTTPError | TimeoutError | Error) => void | Promise<void>;
27}
28
29export interface KyConfig extends Options {
30 retries?: number;
31 timeout?: number;
32}
33
34export interface KyOptions extends Options {
35 retries?: number;
36 timeout?: number;
37 immediate?: boolean;
38 plugins?: KyPlugin[];
39}
40
41export interface KyResult<T> {
42 data: T | null;
43 error: HTTPError | TimeoutError | Error | null;
44 loading: boolean;
45 refetch: () => Promise<T | null>;
46 abort: () => void;
47 aborted: boolean;
48}
49
50export interface KyContextValue {
51 config: KyConfig;
52 updateConfig: (newConfig: Partial<KyConfig>) => void;
53 instance: KyInstance;
54 request: (url: string, options?: Options) => Promise<KyResponse>;
55}
56
57export interface KyProviderProps {
58 config?: KyConfig;
59 children: ReactNode;
60}
61
62// #endregion
63
64// #region Context
65
66const KyContext = createContext<KyContextValue | null>(null);
67
68export function KyProvider({ config = {}, children }: KyProviderProps) {
69 const [currentConfig, setCurrentConfig] = useState<KyConfig>(config);
70 const instanceRef = useRef<KyInstance | null>(ky.create(config));
71
72 const updateConfig = useCallback((newConfig: Partial<KyConfig>) => {
73 setCurrentConfig((prev) => ({ ...prev, ...newConfig }));
74 }, []);
75
76 // Create or update ky instance when config changes
77 useEffect(() => {
78 instanceRef.current = ky.create(currentConfig);
79 }, [currentConfig]);
80
81 const enhancedRequest = useCallback(
82 async (url: string, options: Options = {}): Promise<KyResponse> => {
83 if (!instanceRef.current) {
84 throw new Error('Ky instance not initialized');
85 }
86
87 return instanceRef.current(url, options);
88 },
89 [],
90 );
91
92 const contextValue: KyContextValue = {
93 config: currentConfig,
94 updateConfig,
95 instance: instanceRef.current!,
96 request: enhancedRequest,
97 };
98
99 return (
100 <KyContext.Provider value={contextValue}>{children}</KyContext.Provider>
101 );
102}
103
104export function useKyContext(): KyContextValue {
105 const context = useContext(KyContext);
106 if (!context) {
107// … truncated

Files it writes

  • registry/hooks/use-ky.tsx

Facts

Registry
guarahooks
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-10
Last confirmed
today

Go to the source

guarahooks.com h3rmel/guarahooks on GitHub Raw registry item This item as JSON

More from guarahooks

All 100 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
UseAbortControlleruse-abort-controllerguarahooksHooksFreeno deps
UseArrayStateuse-array-stateguarahooksHooksFreeno deps
UseAxiosuse-axiosguarahooksHooksFreeno deps
UseBatteryStatususe-battery-statusguarahooksHooksFreeno deps
UseBetterAuthuse-better-authguarahooksHooksFreeno deps
UseClickOutsideuse-click-outsideguarahooksHooksFreeno deps
UseConfirmuse-confirmguarahooksHooksFreeno deps
UseCookieuse-cookieguarahooksHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex