jMc*_*McG 1 javascript reactjs redux redux-thunk axios
我已经用这个标题倾注了所有问题,但我找不到可以防止此错误的解决方案.我到目前为止所尝试的是确保我不会混淆新旧redux api,我正在使用babel进行转换,所以没有打字原则解决方案适用,我已经确保我在相关动作中返回一个函数,我已经注释掉我的导入或thunk以确保它中断并且我在导入它之后注销了thunk并且我得到了一个函数,并且我已经从depricated版本更新了devtools扩展.没有成功.任何帮助深表感谢.相关代码如下:
商店:
const redux = require('redux');
const {combineReducers, createStore, compose, applyMiddleware} = require('redux');
import {default as thunk} from 'redux-thunk';
const {nameReducer, hobbyReducer, movieReducer, mapReducer} = require('./../reducers/index');
export const configure = () => {
const reducer = combineReducers({
name: nameReducer,
hobbies: hobbyReducer,
movies: movieReducer,
map: mapReducer
});
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, composeEnhancers(applyMiddleware(thunk)));
return store;
};
Run Code Online (Sandbox Code Playgroud)
操作:
export let startLocationFetch = () => {type: 'START_LOCATION_FETCH'};
export let completeLocationFetch = (url) => {type: 'COMPLETE_LOCATION_FETCH', url};
export let fetchLocation = () => (dispatch, getState) => {
dispatch(startLocationFetch());
axios.get('http://ipinfo.io').then(function(res) {
let loc = res.data.loc;
let baseURL = 'http://maps.google.com?q=';
dispatch(completeLocationFetch(baseURL + loc));
});
};
Run Code Online (Sandbox Code Playgroud)
调度行动的代码:
console.log('starting redux example');
const actions = require('./actions/index');
const store = require('./store/configureStore').configure();
let unsubscribe = store.subscribe(() => {
let state = store.getState();
if(state.map.isFetching){
document.getElementById('app').innerHTML = 'Loading...';
} else if(state.map.url){
document.getElementById('app').innerHTML = '<a target=_blank href = "' + state.map.url + '">Location</a>';
}
});
store.dispatch(actions.fetchLocation());
Run Code Online (Sandbox Code Playgroud)
我现在正在学习React/Redux(这是一门课程)所以我真的可能会错过一些明显的东西.如果我遗漏了相关的内容,请告诉我.谢谢
export let startLocationFetch = () => {type: 'START_LOCATION_FETCH'};
Run Code Online (Sandbox Code Playgroud)
不返回对象,但应该导致语法错误.
要从箭头函数直接返回对象,您需要设置括号,否则它将被解释为块:
export let startLocationFetch = () => ({type: 'START_LOCATION_FETCH'});
Run Code Online (Sandbox Code Playgroud)
编辑:感谢Nicholas指出这确实不是语法错误.
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |