createContext is a helper function that guards against accessing a Context whose value wasn't provided. By doing this, API instead, we never have to provide a default and nver have to check for undefined.


import { createContext } from '@dwarvesf/react-utils'


const [CurrentUserProvider, useCurrentUserName] = createContext<string>({});
function EnthusasticGreeting() {
const currentUser = useCurrentUserName();
return <div>HELLO {currentUser.toUpperCase()}!</div>;
function App() {
return (
<CurrentUserProvider value="Anders">
<EnthusasticGreeting />
Edit this page

Made with ❤️ by Dwarves Foundation