React Native(Netflix app)Android构建错误 - “无法在Connect(App)的上下文或道具中找到'store'”

时间:2017-09-07 03:29:17

标签: javascript android ios react-native netflix

我正在尝试使用来自https://github.com/mariodev12/react-native-netflix的这个GitHub项目来制作像'Netflix'应用程序的android构建版本。由于它是一个反应原生项目, 在iOS中运行良好。但是在使用android构建时,会导致以下错误: '无法在“Connect(App)”的上下文或道具中找到“store”将根组件包装在或明确地将“store”作为道具传递给“Connect(App)”

index.android.js的代码如下:

import { AppRegistry } from 'react-native';
import App from './src/app'
AppRegistry.registerComponent('NetflixApp', () => App);

和App.js是:

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

import {connect} from 'react-redux'

import Header from './components/Header'
import List from './components/List'
import Menu from './components/Menu'
import Slide from './components/Slider'
import Genres from './components/Genres'

import SideMenu from 'react-native-side-menu'

class App extends Component {
    constructor(props){
        super(props)
        this.state = {
            isOpen: false,
            itemSelected: 'Home'
        }
        this.getTwoRows = this.getTwoRows.bind(this)
        this.itemSelected = this.itemSelected.bind(this)
    }

    static navigationOptions = {
        headerVisible: false
    }

    toggle(){
        this.setState({
            isOpen: !this.state.isOpen
        })
    }

    itemSelected(item){
        this.setState({
            itemSelected: item,
            isOpen: false
        })
    }

    updateMenu(isOpen){
        this.setState({isOpen})
    }

    getTwoRows(){
        const {shows} = this.props
        const array = shows.slice(0)
        const val = Math.floor(array.length / 2)
        const newArray = array.splice(0, val)
        return [
            array,
            newArray
        ]
    }

    render(){
        return (
            <View style={{flex: 1}}>
                <SideMenu
                    menu={<Menu 
                        navigation={this.props.navigation}
                        itemSelected={this.itemSelected} 
                        itemSelectedValue={this.state.itemSelected}
                    />}
                    isOpen={this.state.isOpen}
                    onChange={(isOpen) => this.updateMenu(isOpen)}
                    style={{flex: 1}}
                >
                    <View style={[{flex: 1}, styles.container]}>
                        <Header navigation={this.props.navigation} toggle={this.toggle.bind(this)} />
                        {this.state.itemSelected == 'Home' ? <View style={{flex: 1}}>
                            <Slide />
                            <List
                                getTwoRows={this.getTwoRows} 
                                navigation={this.props.navigation}
                            />
                        </View> : 
                        <Genres
                            navigation={this.props.navigation} 
                            item={this.state.itemSelected}
                        />}
                    </View>
                </SideMenu>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        backgroundColor: 'black'
    }
})

export default connect(state => ({shows: state.shows}))(App)

过去一周,我正在努力解决这个问题。你能帮我解决这个问题吗?感谢。

2 个答案:

答案 0 :(得分:0)

Android和iOS索引指向不同的app文件。由于缺少提供给app.js文件的提供程序而导致此错误消息。您可以尝试使用Provider包装返回内容,就像设置index.js文件一样。

答案 1 :(得分:0)

您缺少创建redux商店的部分,并使用Provider将其提供给您的组件。有关详细信息,请查看Redux docs

import { AppRegistry } from 'react-native';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import App from './src/app'

const store = createStore(/* your reducers / middleware */);

const AppWithStore = () => (
  <Provider store={store}>
    <App />
  </Provider>
)

AppRegistry.registerComponent(&#39; NetflixApp&#39;,()=&gt; AppWithStore);