welldone-software / why-did-you-render

why-did-you-render by Welldone Software monkey patches React to notify you about potentially avoidable re-renders. (Works with React Native as well.)
https://www.npmjs.com/package/@welldone-software/why-did-you-render
MIT License
11.11k stars 196 forks source link

Instruction for bare react-native projects #288

Closed sergeylaptev closed 7 months ago

sergeylaptev commented 7 months ago

Just successfully got the library for bare react-native (0.73.2) project working again. Unfortunately, the metro-react-native-babel-preset that comes with react-native out of the box does not allow you to change the options of the babel/plugin-transform-react-jsx plugin. Just add the plugin with options as listed below and start react-native packager as usual. Default env for babel is "development". If you do not use expo when working with react-native, the following method will help you:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],

  env: {
    development: {
      plugins: [['@babel/plugin-transform-react-jsx', { runtime: 'classic' }]],
    },
  },
}
image
vzaidman commented 7 months ago

Thank you!