preact#Context TypeScript Examples
The following examples show how to use
preact#Context.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: getConfig.ts From gridjs with MIT License | 6 votes |
/**
* This is a hack to get the current global config from Preact context.
* My assumption is that we only need one global context which is the ConfigContext
*
* @param context
*/
export default function getConfig(context: {
[key: string]: Context<any>;
}): Config {
if (!context) return null;
const keys = Object.keys(context);
if (keys.length) {
// TODO: can we use a better way to capture and return the Config context?
const ctx: any = context[keys[0]];
return ctx.props.value;
}
return null;
}
Example #2
Source File: container.tsx From gridjs with MIT License | 5 votes |
private readonly configContext: Context<Config>;