React: Can't validate value prop of Context Provider using PropTypes

Created on 18 Apr 2018  路  5Comments  路  Source: facebook/react

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.

Most helpful comment

@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?
    };

All 5 comments

PR here: #12658

@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?
    };

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

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

Was this page helpful?
0 / 5 - 0 ratings