我正在尝试将一个按钮连接到后端,但是我在某个地方出错了,我需要一些建议,这样我就可以克服这一难题。
在操作文件中,我的deleteAccount函数没有移到第一个返回中。它将在控制台中输出已达到确认的信息。我迷失了为什么它不会继续,但我知道我缺少的一些基本知识。任何建议表示赞赏
动作文件
export const deletingAccount = () => {
return {
type: DELETING_ACCOUNT
};
};
export const accountDeletedSuccess = () => {
return {
type: ACCOUNT_DELETED_SUCCESS,
};
};
export const accountDeleteFail = err => {
return {
type: ACCOUNT_DELETE_FAIL,
payload: {err}
};
};
export const deleteAccount = uuid => {
if(window.confirm('Are you sure? This can NOT be undone!')) {
console.log('reached confirm')
return async dispatch => {
console.log('reached dispatch')
dispatch(deletingAccount());
setAuthHeaders(axios);
await axios.delete(`${ROOT_API_URL}/api/user/removeUser/${uuid}`)
.then(data => {
if (data.status === 200) {
return dispatch(accountDeletedSuccess());
}
return dispatch(accountDeleteFail());
})
.catch(err => accountDeleteFail(err));
}
}
};
带有按钮的文件
render() {
return (
<div className="user-edit-profile-content">
<h2 className="edit-profile-title">
Account
</h2>
<div>
<h4>
Delete all posts
</h4>
<h5>Delete everything you posted in the marketplace and services.</h5>
<button className="user-profile-edit-button btn-white" onClick={this.editPageClick}>
Delete
</button>
</div>
<br></br>
<div>
<h4>
Delete account
</h4>
<h5>Delete account. This action cannot be undone.</h5>
<button className="user-profile-edit-button btn-white" onClick={() => deleteAccount()}>
Delete
</button>
</div>
</div>
);
}
}
AccountSettingsContainer.propTypes = {
deleteAccount: PropTypes.func.isRequired
};
const mapStateToProps = (state) => {
return {
user: state.user.user,
}
};
export default withRouter(connect(mapStateToProps, {...Actions, deleteAccount })(AccountSettingsContainer));