babel-plugin-transform-dev-warning icon indicating copy to clipboard operation
babel-plugin-transform-dev-warning copied to clipboard

React.warn/error

Open diegohaz opened this issue 6 years ago • 3 comments

https://github.com/facebook/react/pull/15170 https://twitter.com/brian_d_vaughn/status/1108788282966433792

diegohaz avatar Mar 21 '19 17:03 diegohaz

@diegohaz Thank you for opening this issue. I'm happy to see these two new helpers in React core. I'm not sure how we should handle them.

oliviertassinari avatar Mar 25 '19 09:03 oliviertassinari

I'm not sure too. I guess I'll just update my warning function implementation to use React.warn instead of console.warn when it gets released, so this package is still useful as it is.

diegohaz avatar Mar 27 '19 05:03 diegohaz

We will have to write a branch statement with React.warn, the overhead of adding an extra !== production condition is small. Maybe we should deprecate this babel plugin 🤔.

In Material-UI, we tend to use a custom propType as much as possible for the warning. For instance:

  /**
   * If `true`, the shrink animation is disabled.
   * This only works if variant is `indeterminate`.
   */
  disableShrink: chainPropTypes(PropTypes.bool, props => {
    if (props.disableShrink && props.variant !== 'indeterminate') {
      return new Error(
        'Material-UI: you have provided the `disableShrink` property ' +
          'with a variant other than `indeterminate`. This will have no effect.',
      );
    }

    return null;
  }),

oliviertassinari avatar Mar 27 '19 09:03 oliviertassinari