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

mutuallyExclusiveProps is unintuitive / poorly documented #56

Open
pillowfication opened this issue Apr 5, 2019 · 0 comments
Open

mutuallyExclusiveProps is unintuitive / poorly documented #56

pillowfication opened this issue Apr 5, 2019 · 0 comments

Comments

@pillowfication
Copy link

pillowfication commented Apr 5, 2019

mutuallyExclusiveProps() only checks that at least one exclusive prop is provided. Otherwise it throws with at least one prop that is mutually exclusive with this propType is required. However, two exclusive props are required for mutuallyExclusiveProps() to do anything, since the current propName is not considered an exclusive prop.

// All equivalent
foo: mutuallyExclusiveProps(validator, 'foo')
foo: mutuallyExclusiveProps(validator, 'bar')
foo: mutuallyExclusiveProps(validator, 'foo').isRequired
foo: mutuallyExclusiveProps(validator, 'bar').isRequired
foo: validator

The behavior of mutuallyExclusiveProps().isRequired is unclear. The only requirement is that

it('fails when required, and one of the exclusive props is null/undefined')

and this doesn't describe the current behavior of .isRequired. Currently, if the current propName is not listed as an exclusive prop, then mutuallyExclusiveProps() behaves the exact same as mutuallyExclusiveProps().isRequired. If the current propName is included as an exclusive prop, then the only difference is that propName={null/undefined} is additionally considered as a set prop.

This seems strange because of the following scenario:

Component.propTypes = {
  foo: mutuallyExclusiveProps(any, 'foo', 'bar').isRequired
}

<Component bar /> // passes
<Component foo={null} bar /> // fails
<Component foo={undefined} bar /> // fails
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

1 participant