【发布时间】:2016-12-30 11:47:05
【问题描述】:
我正在使用 React Native 来构建 Android 应用
我正在尝试从位于 app/containers/AppContainer.js 的文件夹中导入 index.android.js 文件中的 组件 >.
当我运行代码时,我得到了这个错误:
元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。检查App的渲染方法
这是我的 index.android.js 文件:
import React, { Component } from 'react';
import { createStore,Provider, applyMiddleware, combineReduxers, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import { AppRegistry } from 'react-native';
import { expect,assert } from 'chai';
import reducer from './app/reducers';
import AppContainer from './app/containers/AppContainer'
const loggerMiddleware = createLogger({ predicate: (getState,action) => __DEV__ });
function configureStore (initialState) {
const enhancer = compose(
applyMiddleware(
thunkMiddleware,
loggerMiddleware,
),
);
return createStore(reducer, initialState, enhancer);
}
const store = configureStore({});
const App = () => (
<Provider store={store}>
<AppContainer />
</Provider>
)
AppRegistry.registerComponent('Appetizing', () => App);
这是我的 AppContainer.js 文件:
import React, { Component } from 'react'
import ReactNative from 'react-native'
const {
View,
Text,
} = ReactNative
class AppContainer extends Component{
render(){
return <View>
<Text style={{marginTop: 20}}>
I am app container
</Text>
</View>
}
}
export default AppContainer
【问题讨论】:
-
你试过
import {AppContainer} from './app/containers/AppContainer'吗? -
@G0dsquad 是的,不起作用。我遇到了同样的错误。
-
如果我包含组件并在标准视图中呈现它,您的代码实际上对我来说很好。 home.js(而不是
index.android.js)。
标签: javascript android react-native redux