Files
buzz-sheet/components/comments/comment-locale.tsx
T
gunshiz 9580407a90
CI / Verify (push) Successful in 1m56s
CI / Build immutable images and deploy (push) Successful in 3m12s
perf : cache
2026-10-08 23:21:34 +07:00

18 lines
744 B
TypeScript

"use client";
import { createContext, useCallback, useContext, type ReactNode } from "react";
import { commentRequest, type CommentLocale } from "./client";
const LocaleContext = createContext<CommentLocale>("th");
export function CommentLocaleProvider({ locale, children }: { locale: CommentLocale; children: ReactNode }) {
return <LocaleContext value={locale}>{children}</LocaleContext>;
}
export function useCommentLocale() {
const locale = useContext(LocaleContext);
const t = useCallback((thai: string, english: string) => locale === "en" ? english : thai, [locale]);
const request = useCallback(<T,>(url: string, options?: RequestInit) => commentRequest<T>(url, options, locale), [locale]);
return { locale, t, request };
}