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
[@types/react] createContext – An argument for 'defaultValue' was not provided. #37023
Comments
I'm closing this issue for now. If someone thinks this is a real issue then be free to contribute. |
Not having a default value is keeping my typescript run build from working. Is there any way to make this optional? |
If you want to compile your code without a default value you can init it with
|
Edit: no, #34854 mentions why. AH well. |
I would also try this: It looks like a dirty hack that could lead to future problems. But in my case, I have a class instance as a value for the context, so If I pass it as a default value, it initializes 2 times - in the provider's value prop and here. |
The |
I know this thread is old but here's a solution that doesn't require null checks. interface SomeProps {
/* your interface */
}
const SomeContext = createContext<SomeProps>(null!); |
What about empty obj? |
An empty object will not work if the interface have required fields. I'm doing a cast while this issue is not solved (if it will ever be): // instead of:
// export const SomeContext = createContext<SomeProps>({});
export const SomeContext = createContext({} as SomeProps); |
Is there any reason of why the argument
defaultValue
is not optional here?Docs url: https://reactjs.org/docs/context.html#reactcreatecontext
I have a matching Provider above in the tree, so I should be able to create a context without set a default value or I'm wrong?
The text was updated successfully, but these errors were encountered: