Skip to content

rodw1995/react-create-safe-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-create-safe-context

Helper to create context in TypeScript with no defaultValue, yet no need to check for undefined.

https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#context

Example

import createSafeContext from '@rodw95/react-create-safe-context';

type AuthContextValue = {
  state: 'signedIn' | 'signedOut',
};

const AuthContext = createSafeContext<AuthContextValue>();  
export const useAuthContext = Context.hook;

export default ({ children }) => (
  <AuthContext.Provider value={{ state: 'signedIn' }}>
    {children}
  </AuthContext.Provider>
);

About

Helper to create context in TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published