Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing for Context API where Context defaultValue is null #97

Closed
AlvSovereign opened this issue Mar 19, 2019 · 2 comments
Closed

Typing for Context API where Context defaultValue is null #97

AlvSovereign opened this issue Mar 19, 2019 · 2 comments
Labels
wontfix This will not be worked on

Comments

@AlvSovereign
Copy link

AlvSovereign commented Mar 19, 2019

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
Copy link
Collaborator

swyxio commented Mar 20, 2019

hi, yup i think this is understood for typescript. i'll keep this issue around to see how we can communicate this

@stale
Copy link

stale bot commented Aug 20, 2020

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!

@stale stale bot added the wontfix This will not be worked on label Aug 20, 2020
@swyxio swyxio closed this as completed Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants