Typeconf React SDK provides both server and client side helpers.
Here’s how to use it in a server component:
Copy
import { readConfig } from "@typeconf/react-sdk/server";import { ButtonSettings } from "@/configs/types/all";export default function Component() { // Path to your config without extension const config: ButtonSettings = readConfig("configs/user-settings");}
For client-side configuration you need to add a provider to the layout:
Copy
// app/layout.tsximport { TypeconfProvider } from "@typeconf/react-sdk";import { readConfig } from "@typeconf/react-sdk/server";import { ButtonSettings } from "@/configs/types/all";// other codeexport default async function RootLayout({ children,}: Readonly<{ children: React.ReactNode;}>) { // Path to your config without extension const config: ButtonSettings = readConfig("configs/user-settings"); return ( <html lang="en"> <body> <TypeconfProvider config={config}> {children} </TypeconfProvider> </body> </html> );}
Then in the component you can use the useTypeconf hook:
Copy
import { useTypeconf } from "@typeconf/react-sdk";import { ButtonSettings } from "@/configs/types/all";export default function Component() { const config: ButtonSettings = useTypeconf(); // rest of the component}