我试图共享相同的代码库,所以我将代码写在 index.js
文件中,并将相同的代码放入 index.ios.js
和 index.android.js
文件。
这是 index.ios.js
中的代码:
'use strict';
import React, { AppRegistry } from 'react-native';
import MYCLASS from './index';
AppRegistry.registerComponent('MYCLASS', () => MYCLASS);
这是index.js
中的部分代码:
export default class MYCLASS extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.title}>
my text
</Text>
</View>
);
}
}
最佳答案
您需要更改导入 React 的方式。
有关详细信息,请参阅其他答案:https://stackoverflow.com/a/37415044/158525
关于javascript - 元素类型无效 : expected a string or a class/function but got: object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38063290/