prop-types icon indicating copy to clipboard operation
prop-types copied to clipboard

checkPropTypes: add argument that allows external logging

Open rufman opened this issue 8 years ago • 13 comments

When using prop-types for checking things outside of React, having checkPropTypes throw an error instead of swallowing it and logging it to console.error can be useful. The flag throwErrors will throw the error if set to true instead of logging it. AcheckPropTypeWithErrors convenience function, which calls checkPropTypes with throwErrors set to true has also been added.

Fixes #34

rufman avatar May 17 '17 22:05 rufman

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

facebook-github-bot avatar May 17 '17 22:05 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

facebook-github-bot avatar May 17 '17 22:05 facebook-github-bot

@gaearon Is this a good approach to using prop-types checking outside of React? Or is there a better way?

rufman avatar Jun 12 '17 18:06 rufman

Sorry, we're busy with many other things right now, and it's unlikely we'll have time to review PRs to prop-types very soon. In this PR, a few things concern me:

  • Creating errors is expensive and we'd like to get away from that, but throwing reinforces this pattern
  • This doesn't expose other important information (such as component stack)

gaearon avatar Jun 12 '17 18:06 gaearon

The PR has been updated to not throw an error, but instead calls the function passed in as an argument, with the same arguments as are passed to warning.

rufman avatar Jul 13 '17 03:07 rufman

I'm aware that there might not be time to review this PR, but with React 16 in beta now the resolution on how to use prop-types with custom errors is becoming a more prominent issue.

I was wondering if there is anything else that would need to be done on this PR to have it merged. Or if such a feature won't be considered for the prop-types package, we'll look into alternatives.

rufman avatar Sep 05 '17 18:09 rufman

Any traction here? This is something we're interested in as well.

kaiyoma avatar Sep 28 '17 19:09 kaiyoma

@kaiyoma I used check-prop-types module mentioned here: https://github.com/facebook/prop-types/issues/28#issuecomment-313504898

martinhorsky avatar Sep 29 '17 06:09 martinhorsky

This would also be super useful to me. Any word on whether this might make it in? If it won't, then closing this PR and "officially" referring users to another project that does this might be a good move.

JoeDuncko avatar Jun 29 '18 18:06 JoeDuncko

Any update or ETA here?

jkusa avatar Mar 06 '20 14:03 jkusa

Man I sure could use this right now. Any updates?

cythrawll avatar Mar 23 '20 20:03 cythrawll

oh my gosh so close, would love to see this added to the library, for sure.

JimmayVV avatar May 07 '20 21:05 JimmayVV

This has been here for quite a while, and have read little to no objections to merging this PR aside from "time" constraints. This would be a wonderful addition to the propTypes library and I am genuinely confused as to what it would take to consider merging it.

JimmayVV avatar Jul 30 '21 15:07 JimmayVV