我正在使用react,react-redux
,redux
。然后我遇到了问题。 当我使用:使用applyMiddleware时,无法监听状态发生改变createStore()
const store = createStore(reducers);
store.subscribe(() => {
console.log(getState());
});
=>结果:我可以看到价值的getState()当我使用派遣一些动作来更新/获取/ ...等状态来改变。但如果我使用applyMiddleware。我不会看到值处于状态改变时,有任何动作
import indexService from './dashboard/services/services.jsx';
const store = createStore(reducers, applyMiddleware(indexService));
store.dispatch({ type: 'DASHBOARD_GET_CURRENT_DEALS' });
这是indexService
组件
import { config } from '../../helps.jsx';
const indexService = store => next => action => {
switch (action.type) {
case 'DASHBOARD_GET_CURRENT_DEALS':
fetch(config.homeUrl + '/data/_curentDeals.json', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
}).then(function (response) { return response.json() }).then(function (json) {
next({
type: 'DASHBOARD_GET_CURRENT_DEALS',
json
})
}).catch(function (error) { console.log('erros', error); });
break;
default:
break;
}
};
export default indexService;
感谢您的帮助;
谢谢你。 我试过了,但它仍然没有工作。 –
非常感谢你。我的错 。我错过了“**下一步(行动); **” –
:),我也乍一看错过 –