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

Children of children / recursive validation #50

Open
SelaO opened this issue Feb 4, 2019 · 3 comments
Open

Children of children / recursive validation #50

SelaO opened this issue Feb 4, 2019 · 3 comments

Comments

@SelaO
Copy link

SelaO commented Feb 4, 2019

I want to validate the children of an element that's passed as children.

For example:

<x><y/></x>

Where y is wrapped with injectIntl and, so I want to check in x that y is either of type "A" or type "B", but because it's wrapped, I need to go one level deep.

Is there a way to do this with these proptypes?

childrenOfType doesn't help because it can only check if it's of type injectIntl.

@ljharb
Copy link
Owner

ljharb commented Feb 4, 2019

I'm not sure what you're asking - can you provide the actual component code?

@SelaO
Copy link
Author

SelaO commented Feb 6, 2019

Foo:

class Foo extends Component {

};
...
export default injectIntl(Foo);

Bar:

export default class Bar extends Component {

  render() {
    const Foo = this.props.foo;
    return <Foo />;
  }
}

FormDropZoneWrapper.propTypes = {
  dropZoneComponent: PropTypes.func.isRequired, // I want here to validate that Foo is actually Foo and not some other component, but it's wrapped by intl so I can't
};

See the comment.

@ljharb
Copy link
Owner

ljharb commented Feb 6, 2019

In that case, you'd use PropTypes.oneOf([Foo]) - iow, nobody can ever get at the unwrapped Foo, only the wrapped one, so you only have to validate that it's the wrapped one.

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

2 participants