gpt4 book ai didi

javascript - 如何在 React Native 中使用 index.js 而不是 (index.ios.js, index.android.js) 进行跨平台应用程序?

转载 作者:IT老高 更新时间:2023-10-28 23:28:03 31 4
gpt4 key购买 nike

感谢您从现在开始的回答,

我是React Native的新手,我想做一个跨平台的应用所以我创建了index.js:

import React from 'react';
import {
Component,
View,
Text,
} from 'react-native';

class ReactApp extends Component {

render() {
return (
<View><Text>Hello world</Text></View>
);
}
}

module.exports = ReactApp;

然后我像这样从 index.ios.js 和 index.android.js 导入 index.js:

import { AppRegistry } from 'react-native';
import ReactApp from './index';

AppRegistry.registerComponent('ReactApp', () => ReactApp);

我认为在此之后它应该可以工作,但我明白了错误:

enter image description here

最佳答案

在 React v0.49 之后,您不再需要 index.ios.jsindex.android.js。你只需要 index.js:

import {AppRegistry} from 'react-native';
import App from './app/App';

AppRegistry.registerComponent('appMobile', () => App);

(将 appMobile 替换为您的应用名称)

来源:(https://github.com/facebook/react-native/releases/tag/v0.49.0)

New projects have a single entry-point (index.js) from now on

关于javascript - 如何在 React Native 中使用 index.js 而不是 (index.ios.js, index.android.js) 进行跨平台应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44803681/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com