You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a component with a sub-component API and I want to validate that the children of the component are a part of that sub-component API. The childrenOfType validator lets me do this (thanks!), but I have discovered an edge case that could be solved with slight modification to the existing validator. The edge case is when a fragment is used to wrap the children. For example, consider the following sub-component API + component prop-types spec:
Now, if I am conditionally rendering the children of the component and a case where multiple child elements are the resulting expression I need to wrap those with a fragment so that it is valid JSX. This causes childrenOfType to err.
<Component>{someCondition ? (<><Component.A>Some content</Component.A><Component.B>Some more content</Component.B></>) : (<Component.A>
Some other content
</Component.A>)}</Component>
I do realize that the above could be solved by writing the conditional differently, however, I do think that it seems reasonable for the childrenOfType validator to recognize a fragment as a non-element and to forward its checking of the children to the fragment. Thoughts?
The text was updated successfully, but these errors were encountered:
I have a component with a sub-component API and I want to validate that the children of the component are a part of that sub-component API. The
childrenOfType
validator lets me do this (thanks!), but I have discovered an edge case that could be solved with slight modification to the existing validator. The edge case is when a fragment is used to wrap the children. For example, consider the following sub-component API + component prop-types spec:Now, if I am conditionally rendering the children of the component and a case where multiple child elements are the resulting expression I need to wrap those with a fragment so that it is valid JSX. This causes
childrenOfType
to err.I do realize that the above could be solved by writing the conditional differently, however, I do think that it seems reasonable for the
childrenOfType
validator to recognize a fragment as a non-element and to forward its checking of the children to the fragment. Thoughts?The text was updated successfully, but these errors were encountered: