Andy Andy - 1 year ago 140
React JSX Question

is there any way to disable or speed up React PropType validation in development mode?

As far as I know the only way to disable React PropType validation is to uglify React with

defined to be

However, I would like to use development mode without runtime PropType validation for the following reasons:

  • They slow down my app significantly. PropType validation is the top offender in profiling results because:

    • I have a fairly deep component hierarchy with PropType validation at multiple levels (yes I do have proper shouldComponentUpdate etc.)

    • I'm using Redux, which means all updates start at or near the top of the hierarchy

    • I have mouse drag interactions which strive for 30 updates per second

  • I still want to see all other React warnings and errors, which would also get disabled in production mode.

  • Flowtype can apparently statically validate PropTypes in a lot of cases anyway.

If nothing else I could create a transformer for
that strips away all components'
(or perhaps only those of components I've annotated in a certain way), but I'm wondering if there's a simpler way to do it, because React could easily provide a compile-time flag to disable PropType validation.

Answer Source

Short answer: There is no simple flag to disable only PropType validation

Currently, PropType validation is enabled by __DEV__ global variable. If it's changed to false, you will lose other React warnings and errors that, as you said, you can't.

This code here in ReactDOMFactories shows how ReactElementValidator and ReactElement factories are chosen to define how an element creation will work.

In ReactElementValidator.createElement you can see that it calls ReactElement.createElement and then validatePropTypes.

I'm not sure how this information can help you but at least shows that there is no simple way to disable PropType by a flag as you wondered.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download