Typing for Context API where Context defaultValue is `null`
AlvSovereign opened this issue · 2 comments
AlvSovereign commented
Hi there
There are times where we want the defaultValue for React's Context API to be null
.
I've found this solution.
TLDR:
import * as React from 'react';
interface AppContextInterface {
name: string,
author: string,
url: string
}
const {Provider, Consumer} = React.createContext<AppContextInterface | null>(null);
Now we can pass null
in as a default value as our React.createContext
argument.
swyxio commented
hi, yup i think this is understood for typescript. i'll keep this issue around to see how we can communicate this
stale commented
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!