mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: split hooks
This commit is contained in:
1 parent
67024daa25
commit
1a18058228
4 files changed
+16
-14
No files matched your search
@@ -3,11 +3,10 @@ import { useAwait } from "./useAwait";
|
||||
import { useLocale } from "./useLocale";
|
||||
|
||||
export function useGameStrings(group: string) {
|
||||
const { locale } = useLocale();
|
||||
const locale = useLocale();
|
||||
const strings = useAwait(
|
||||
() => api.groupedGameStrings(locale, group, true),
|
||||
`game-strings-${locale}-${group}`
|
||||
);
|
||||
|
||||
return strings;
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { createContext, useContext, type ReactNode } from "react";
|
||||
import { api } from "../core/api/dynamic";
|
||||
import { useAwait } from "./useAwait";
|
||||
|
||||
const LocaleContext = createContext<{
|
||||
locale: string;
|
||||
@@ -26,12 +24,7 @@ export function useLocale() {
|
||||
throw new Error("useLocale must be used within a LocaleProvider");
|
||||
}
|
||||
|
||||
const strings = useAwait(
|
||||
() => api.strings(context.locale),
|
||||
`strings-${context.locale}`
|
||||
);
|
||||
|
||||
return { locale: context.locale, strings };
|
||||
return context.locale;
|
||||
}
|
||||
|
||||
export interface LocaleAcceptorProps {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { api } from "../core/api/dynamic";
|
||||
import { useAwait } from "./useAwait";
|
||||
import { useLocale } from "./useLocale";
|
||||
|
||||
export function useStrings() {
|
||||
const locale = useLocale();
|
||||
const strings = useAwait(() => api.strings(locale), `strings-${locale}`);
|
||||
return strings;
|
||||
}
|
||||
Reference in new issue
Block a user