我试图在进行axios调用之前通过验证测试,但不确定如何在验证或立即发送请求的过程中正确实现它。
在我名为“ main.jsx”的主容器中,
const mapDispatchToProps = dispatch => {
return {
sendRequest: (query) => dispatch(request_house(query))
};
};
然后按照我的动作
import * as actionTypes from './actionTypes'
import serverConnect from "../../axios/connection";
export const set_house = (response) =>{
return {
type: actionTypes.SET_HOUSE,
response,
}
}
export const set_error = () =>{
return {
type: actionTypes.SET_ERROR
}
}
export const validate_request = (query) =>{
return {
type: actionTypes.VALIDATE_REQUEST,
query
}
}
export const request_house = (query) =>{
return dispatch =>{
serverConnect.post(`/searchHouse/${query}`).then(response => {
dispatch(set_house(response))
}).catch(()=>{
dispatch(set_error)
});
}
}
是否可以在发出请求之前分派验证调用?我应该如何处理?