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

Can't validate value prop of Context Provider using PropTypes #12636

Closed
SamSamskies opened this issue Apr 18, 2018 · 5 comments
Closed

Can't validate value prop of Context Provider using PropTypes #12636

SamSamskies opened this issue Apr 18, 2018 · 5 comments

Comments

@SamSamskies
Copy link

Do you want to request a feature or report a bug?
Not sure if this is a bug or a feature request.

What is the current behavior?
Can't validate value prop of a Context Provider using PropTypes

See CodeSandbox example here: https://codesandbox.io/s/1z1oxpx02j

screen shot 2018-04-17 at 8 36 13 pm

What is the expected behavior?
Expected PropTypes violation warning in the console

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
v16.3.2

I'd be happy to implement this if others also wish it was possible to validate the value of the Context Provider using PropTypes. It would help if someone pointed me in the right direction though. I haven't dug into the React internals much yet.

@wherestheguac
Copy link
Contributor

PR here: #12658

@gaearon
Copy link
Collaborator

gaearon commented Apr 22, 2018

Fixed by @nicolevy in #12658 (comment)

@gaearon gaearon closed this as completed Apr 22, 2018
@damianobarbati
Copy link

damianobarbati commented Oct 31, 2018

@gaearon @nicolevy @SamSamskies I didn't understand from the #12658 how to add props validation to context values. Can you please document this?

export default class Form extends React.Component {
    static contextType = context;
    
    static propTypes = {
       i do say I expect a "values" key in context which should in turn be an object?
    };

@amitpatil321
Copy link

@damianobarbati Same with me, i have gone through it and didn't understand how to use it. An example would be appreciated.

@SamSamskies
Copy link
Author

Hey @damianobarbati and @amitpatil321, check out an example here: https://codesandbox.io/s/1z1oxpx02j

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants