react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
37 lines • 1.09 kB
TypeScript
/**
* Creates a new datastore for a given server context.
* Attempts to closely mimic the `createContext` API.
*
* @example
* const IntlayerServer = createServerContext<string | null>(null);
*
* <IntlayerServer value={locale}>
* {children}
* </IntlayerServer>
*/
import { type FC, type PropsWithChildren, type ReactNode } from 'react';
export declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
/**
* Fetches a value present in a given server context.
* Attempts to closely mimic the `useContext` API.
*
* @example
* getServerContext(IntlayerServer);
*/
export declare const getServerContext: <T>({ _storage, _defaultValue, }: ServerContext<T>) => T;
type ServerContext<T> = FC<PropsWithChildren<{
value?: T;
}>> & {
Provider: FC<PropsWithChildren<{
value?: T;
}>>;
Consumer: FC<PropsWithChildren<{
children: (context: T | undefined) => ReactNode;
}>>;
_storage: () => {
value: T | undefined;
};
_defaultValue: T | undefined;
};
export {};
//# sourceMappingURL=serverContext.d.ts.map