mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
63cd906cfc
- Merge all files inside openflare-server to the repository root directory. - Relocate agent, relay, and flared subprojects from internal/ to internal/apps/. - Combine docker-compose files and update build context paths to root. - Update GitHub workflows and Dockerfiles to refer to new directories and package names. - Rewrite Go package imports across all files. - Resolve database renew test race condition and clean up docs.
37 lines
749 B
TypeScript
37 lines
749 B
TypeScript
import * as React from 'react';
|
|
|
|
function getStrictContext<T>(
|
|
name?: string,
|
|
): readonly [
|
|
({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: T;
|
|
children?: React.ReactNode;
|
|
}) => React.JSX.Element,
|
|
() => T,
|
|
] {
|
|
const Context = React.createContext<T | undefined>(undefined);
|
|
|
|
const Provider = ({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: T;
|
|
children?: React.ReactNode;
|
|
}) => <Context.Provider value={value}>{children}</Context.Provider>;
|
|
|
|
const useSafeContext = () => {
|
|
const ctx = React.useContext(Context);
|
|
if (ctx === undefined) {
|
|
throw new Error(`useContext must be used within ${name ?? 'a Provider'}`);
|
|
}
|
|
return ctx;
|
|
};
|
|
|
|
return [Provider, useSafeContext] as const;
|
|
}
|
|
|
|
export { getStrictContext };
|