react: False positive getDefaultProps warning when mixing development and production versions

As migrating from 15.4 to 15.5, I am rewrite original react components with create-react-class.

However, there is a warning.

react-15.5.4.js?bust=1497843639843:3287 Warning: getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.

As I am really transferring from a classic React.createClass definition, I would like to ask is this warning appropriate? Or, this is a depreciation sames as the level of migrating to create-react-class?

Ooops, I get ticket #9999 😄

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 24
  • Comments: 39 (4 by maintainers)

Most upvoted comments

Hi! Is this work still needed? I’m looking to grab a first issue to contribute to, but after spending some time on this thread it seems to have been just left out.

is anyone Working on this issue Can i?

To be honest, i am not sure. Hopefully, it was fixed a long time ago.

On Thu, 15 Jun 2023, 18:51 Ashish Padhy, @.***> wrote:

Hey @mondwan https://github.com/mondwan is this still relevant?

— Reply to this email directly, view it on GitHub https://github.com/facebook/react/issues/9999#issuecomment-1593497822, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5YBI2SOEVVG4JGQRL6LZDXLNDS5ANCNFSM4DPXD3KQ . You are receiving this because you were mentioned.Message ID: @.***>

Because getDefaultProps is only used for components created with createReactClass. For example, the warning will catch cases where someone is moving from createClass to ES6 classes and they forget to remove getDefaultProps in favor of defaultProps.

You’ll never get the warning when using the correct build of create-react-class. It’s also important to use minified bundles for react and react-dom in production, as they’re much more performant. On the same token, it’s useful to use the unminified build in development as it contains a sizeable set of useful checks and warnings.

No, to fix the false positive warnings, you need to either use:

  • react.js and create-react-class.js (development)
  • react.min.js and create-react-class.min.js (production)

The mistaken warning occur when you mix development and production versions of these two libraries.

is this issue resolved?

@mondwan the issue is that you’re using the minified create-react-class build, but the unminified react build. This means that the internal flag that create-react-class uses to suppress this warning is not applied, so React warns.

Make sure you use the correct build for your environment (minified for production, unminified for development).

@techwizard31 grow up bud!

Nah, it’s all you. Went into the rabbit hole of chatbots 😄

On Sun, Sep 16, 2018 at 3:25 PM, Charlie Truong notifications@github.com wrote:

@benschac https://github.com/benschac Are you still poking at this? Would like to take a crack at it if it’s not being worked on.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/react/issues/9999#issuecomment-421817173, or mute the thread https://github.com/notifications/unsubscribe-auth/ACYxIyHoAHEwkH-qRLXtJw9hTYI-ZAuxks5ubqWYgaJpZM4N9x7V .

It would still be nice if there was a way to avoid the false positive as this is pretty confusing. Maybe we can turn a flag into a number, and always set it in DEV. If it’s not set then we’re in PROD mode and shouldn’t check.

You’re getting the warning because you’re using the production create-react-class build with the development react build. The production build strips out the code that prevents this warning in development