import { Context, useContext } from 'react'; import { Actions, DakpanContext, DakpanHook } from './types'; export function createHook>(context: Context>): DakpanHook { return (nullable?: boolean) => { const state = useContext(context); if (!state && !nullable) { throw Error('Provider not mounted'); } return [ state && state.state, state && state.actions ] as any; }; }