在Redux不工作的情况下调度操作,得到未捕获的typeError,说它不是一个函数
Dispatched action with Redux not working, getting uncaught typeError, saying it's not a function
我有一个非常简单的动作正在调度,基本上是为了确保一切工作正常。不幸的是,我一直得到:
Uncaught TypeError: _this2.props.testFunction is not a function
我已经检查过了,一切似乎都很好。下面是我的代码:
//index.js
const loggerMiddleware = createLogger();
const middleware = applyMiddleware(thunkMiddleware, loggerMiddleware);
const store = createStore(allReducers, middleware);
export default class Help2 extends Component{
render(){
return (
<Provider store={store}>
<App/>
</Provider>
);
}
}
//reducers/index.js
const allReducers = combineReducers({
topic: TopicsReducer
});
export default allReducers;
//reducer/test-reducers.js
export default function(state=null, action){
switch(action.type){
case 'TEST_REDUCER':
return action.payload; //will return that object
break;
}
return state;
}
//actions.js
export function testFunction(topicsUrl){
console.log('I have been called');
const request= axios.get(topicsUrl);
return (dispatch)=>{
request.then(({data})=>{
dispatch({type: 'TEST_REDUCER', payload: data,});
});
}
};
//container/test.js
export class Test extends Component{
render(){
return(
<div onClick={()=>this.props.testFunction("https://api.someApi.com/")}>Click here to test</div>
);
}
}
function mapStateToProps(state){
return{
topic: state.topic
}
}
function matchDispatchToProps(dispatch){
return bindActionCreators({testFunction: testFunction}, dispatch);
}
export default connect(mapStateToProps, matchDispatchToProps)(Test);
那么,有人知道是哪里出了问题吗?
编辑:修正动作类型
Edit2:这是我在容器/test.js导入的东西
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {testFunction} from '../actions/actions';
figure out:
我使用export default连接和导出我的组件。当只导入组件时。
我真不敢相信我做了那件事!相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 我可以在json对象中添加一个函数吗
- Javascript使函数一个接一个地执行
- 是JavaScript中的函数一个对象
- 两个几乎相等的jQuery函数;一个适用于IE,一个不适用于IE
- 两个Javascript函数一个window.onload=Custom.init;和一个window.onload=f
- 使javascript加载函数一个接一个地执行
- 如何通过两个嵌套的匿名函数(一个带有超时的事件处理程序)传递变量
- 为什么我不能让两个jQuery函数一个在另一个里面呢?
- 给函数一个变量名,而不是它的值
- 如何使用嵌入函数(一个滚动页由Pete - peachananr)
- 是否有可能给JavaScript函数一个类型/类?
- 确保两个函数一个接一个地执行,其中第一个函数内部有一个异步调用
- 两个不同的ajax函数一个接一个调用返回相同的值
- jQuery第一次更改函数一个工作
- 给这个函数一个id
- 如何给回调函数一个值一个变量在特定时刻
- 使用回调使两个函数一个接一个地运行
- 两个函数(一个用php)是否可以用“;onclick”;
- 两个几乎相同的函数.一个函数用Queue进行排队.Jquery效果在queued函数上不起作用.为什么