createStore(reducer)无法正常工作

时间:2019-05-24 05:38:22

标签: reactjs react-native redux

我已经检查了10次代码,但找不到答案。我不断收到此错误:

Invariant Violation: Element type is invalid: expected a string but got: undefined

这是我的代码:

App.js

import React from 'react'
import { View, Text } from 'react-native'
import Provider from 'react-redux'
import { createStore } from 'redux'
import Header from './components/common/Header'
import Button from './components/common/Button'
import NumberLabel from './components/NumberLabel'
import reducers from './reducers/'

class App extends React.Component {

  render() {
    return(
      <Provider store={createStore(reducer)}>
        {/* <View>
          <Header text='Counter'/>
          <NumberLabel />
          <Button text='Add One' onPress={this.incrementButtonPressed}/>
        </View>       */}
      </Provider>
    )
  }
}

export default App

reducers / index.js

import { combineReducers } from 'redux'
import IncrementReducer from './IncrementReducer'

export default combineReducers({
  increment: IncrementReducer
})

reducers / IncrementReducer.js

export default (state, action) => {
  return []
}

1 个答案:

答案 0 :(得分:0)

我认为您应该尝试将Provider用大括号括起来,如下所示:

import { Provider } from 'react-redux';