import React from 'react'; export const useNonNullableContext = ( context: React.Context, name?: string ): NonNullable => { const maybeContext = React.useContext(context); if (maybeContext === null || maybeContext === undefined) { throw new Error(`context "${name}" was used without a Provider`); } return maybeContext; };