我正在尝试在React中学习Redux,我有一个reducer:
减速器/ index.js:
import { combineReducers } from 'redux';
export default combineReducers({
foo: () => []
});
我正在使用以下方式创建我的商店:
import React from 'react';
import { View } from 'react-native';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { reducers } from './reducers'; // ./reducers/index.js is implied
import { Header } from './components/common';
const app = () => (
<Provider store={createStore(reducers)}>
<View>
<Header headerText="Foo App" />
</View>
</Provider>
);
但是为此我得到一个错误:
Console.error:“没有为密钥foo提供reducer”
我只想尝试返回一个空数组。我做错了什么?
答案 0 :(得分:1)
您的错误是导入减速机的方式。您将其导出为默认值,因此您需要删除它周围的花括号。
import reducers from './reducers';
如果您已完成export const reducers //....
,则需要import { reducers } from './reducers';