如何将react 17的新JSX转换与react-native 0.64.0(rc4)一起使用?

Mic*_*oul 5 react-native

问题基本上在标题中,但我已经使用react-native 0.64.0-rc.4创建了演示项目。此版本的 RN 使用 React-17,因此据说还应该能够使用新的 JSX 转换。问题是这是否真的可能,以及如何实现。import React from 'react';当我注释中的行时App.js,应用程序由于未知React变量而创建渲染错误。

MJ *_*dio 9

你可以参考这个评论

我也遇到过同样的问题,只能通过改变来解决babel.config.js

这是我的babel.config.js

关键是useTransformReactJSXExpermiental: trueruntime: 'automatic'

module.exports = {
  presets: [
    ['module:metro-react-native-babel-preset', { useTransformReactJSXExperimental: true }],
    '@babel/preset-typescript',
  ],
  sourceMaps: 'inline',
  plugins: [
    [
      '@babel/plugin-proposal-decorators',
      {
        legacy: true,
      },
    ],
    [
      '@babel/plugin-transform-react-jsx',
      {
        runtime: 'automatic',
      },
    ],
    '@babel/proposal-object-rest-spread',
    ['babel-plugin-styled-components'],
    'react-native-reanimated/plugin',
  ],
};

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述