我正在尝试在我的app.js文件中使用redux持久和react-redux,但是出现以下错误:
不变违反:在“ Connect(App)”的上下文或道具中找不到“商店”。将根组件包装在中,或者将“存储”作为道具明确传递给“ Connect(App)”
这是我的app.js文件的代码,发生错误。
import React from 'react';
import { Provider } from 'react-redux';
import StoreDetailsScreen from './screens/storeDetailsScreen';
import CustomerListScreen from './screens/customerListScreen';
import AddCustomerScreen from './screens/addCustomerScreen'
import AddTransactionsScreen from './screens/addTransactionScreen'
import TransactionListScreen from './screens/transactionListScreen'
import CustomerInfoScreen from './screens/CustomerInfoScreen'
import {connect} from 'react-redux'
import {daysFromTransaction} from './redux/reducer'
import {updateFrequency} from './redux/actions'
import {store, persistor} from './redux/store';
import { createSwitchNavigator, createStackNavigator, createMaterialTopTabNavigator } from 'react-navigation';
import {PersistGate} from 'redux-persist/integration/react'
const TransactionsNavigator = createMaterialTopTabNavigator({
AddTransactions: AddTransactionsScreen,
CustomerInfo: CustomerInfoScreen,
TransactionList: TransactionListScreen,
})
const CustomerNavigator = createStackNavigator({
CustomerList: CustomerListScreen,
AddCustomerForm: AddCustomerScreen,
Transactions: TransactionsNavigator,
});
const MainNavigator = createSwitchNavigator({
StoreDetailsForm: StoreDetailsScreen,
Customers: CustomerNavigator,
});
class App extends React.Component {
state = {
customers: this.props.customers,
isReady: false,
}
async componentWillMount() {
await Expo.Font.loadAsync({
'MaterialIcons': require('@expo/vector-icons/fonts/MaterialIcons.ttf')
});
updatedCustomers = this.state.customers.map(customer => {
let frequency = 0
currentDate = new Date()
customer.transactions.forEach(transaction => {
if (daysFromTransaction(transactionDate, currentDate) < 30)
frequency++;
})
return {
...customer,
frequency: frequency
}
})
this.props.updateFrequency([...updatedCustomers])
this.setState({isReady: true})
}
render() {
if (!this.state.isReady)
return <Expo.AppLoading/>
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<MainNavigator />
</PersistGate>
</Provider>
);
}
}
const mapStateToProps = state => {
customers: state.customers
}
export default connect(mapStateToProps,{updateFrequency: updateFrequency})(App)