Last active
October 14, 2020 12:43
-
-
Save Dremora/7e41c3ff4335a53185299b5ea06698fb to your computer and use it in GitHub Desktop.
Prohibit using React context without provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext } from 'react'; | |
interface SystemStatus { | |
isOnline: boolean; | |
} | |
const SystemStatusContext = createContext<SystemStatus>({ | |
get isOnline(): never { | |
throw new Error('Used outside of SystemStatusContext'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment