【发布时间】:2018-06-25 23:00:02
【问题描述】:
我是新来的反应。我试图将组件和动作功能分开。但我无法从单独的操作函数中获取返回值。是否可以从调度函数返回一个值(例如 Object {})
我把简要代码如下:
LoginComponent.js
class Login extends React.Component {
constructor(props){
super(props)
this.state = {
username : '',
password : ''
}
}
submit = (e) => {
/* console.logging "Some response"*/
console.log(this.props.doLogin(this.state))
}
render(){
return (
<form onSubmit={this.submit}>/* some login element */</form>
)
}
}
export default connect(null, {LoginAction})(Login);
LoginAction.js
export function doLogin(state){
return dispatch => {
return axios.post('login', state).then(res =>{
return "Some response";
})
}
}
但它不返回任何值
谢谢。
【问题讨论】:
标签: reactjs react-redux redux-thunk