Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Ability to verify a prop is a React.Fragment #273

Closed
slorber opened this issue May 13, 2019 · 4 comments
Closed

Ability to verify a prop is a React.Fragment #273

slorber opened this issue May 13, 2019 · 4 comments

Comments

@slorber
Copy link

slorber commented May 13, 2019

@ljharb suggested here to open a new issue to verify react fragment proptypes: #211 (comment)

Just to give more context, for react-intl FormattedMessage component, I'd like to submit a PR to add support for fragments.

Currently the lib has tagName: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),

I want to submit a PR to update to something like tagName: PropTypes.oneOfType([PropTypes.string, PropTypes.element, React.Fragment]),

The lib is able to support fragments at runtime. I'm already using tagName=Fragment. I just want a solution to remove the propTypes warning I have when using Fragments.

I've noticed it works with elementType but I guess my PR wouldn't be accepted by react-intl team as it's a bit too "wide" and less specific

@kuehlein
Copy link

I'm currently using PropTypes.symbol as a work around to suppress the error. I'm not sure if that is specific enough to avoid any possible edge cases though.

@ljharb
Copy link
Contributor

ljharb commented Aug 12, 2019

@slorber PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.oneOf([React.Fragment])) should do it, no?

@slorber
Copy link
Author

slorber commented Aug 13, 2019

Hmmm maybe, didn't try that one ;)

Using TS now so not really using proptypes anymore

@ljharb
Copy link
Contributor

ljharb commented Aug 13, 2019

TS isn’t a replacement for PropTypes; it can check number but not integer; it doesn’t have negated types yet; it can’t do ranges, or many other things. I’d strongly suggest using both.

However. I’ll close this, if you no longer have the feature request.

@ljharb ljharb closed this as completed Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants