mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
30 lines
704 B
TypeScript
30 lines
704 B
TypeScript
|
|
"use client"
|
||
|
|
|
||
|
|
import React, { createContext, useContext } from "react"
|
||
|
|
import type { Dictionary } from "@/lib/i18n/dictionaries"
|
||
|
|
|
||
|
|
const DictionaryContext = createContext<Dictionary | null>(null)
|
||
|
|
|
||
|
|
export function DictionaryProvider({
|
||
|
|
children,
|
||
|
|
dictionary,
|
||
|
|
}: React.PropsWithChildren<{ dictionary: Dictionary }>) {
|
||
|
|
return React.createElement(
|
||
|
|
DictionaryContext.Provider,
|
||
|
|
{ value: dictionary },
|
||
|
|
children,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useDictionary() {
|
||
|
|
const dict = useContext(DictionaryContext)
|
||
|
|
if (!dict) {
|
||
|
|
throw new Error(
|
||
|
|
"useDictionary must be used within a DictionaryProvider",
|
||
|
|
)
|
||
|
|
}
|
||
|
|
return dict
|
||
|
|
}
|
||
|
|
|
||
|
|
export default useDictionary
|