와 디스패치 개체의 나는 코드REDUX 액션, 화살표 기능
const ERROR_MSG = 'ERROR_MSG'
function errorMsg(msg){
return { msg, type:ERROR_MSG }
}
export function register({user,pwd,type}){
return dispatch=>{
axios.post('/user/register', {user,pwd,type})
.then(res=>{
if(res.status!==200){
dispatch(errorMsg(res.data.msg))
}
})
}
}
그것의 파견 PARAM 같은 기능을하고, PARAM 반환 뭔가를받을 아래에서왔다. 나는 그것에 익숙하지 않고 왜 여분의 기능을 만들어야 하는가? errorMsg가 전역이거나 다른 함수가 중복되는 경우에는 의미가 있습니다.
화살표 기능을 사용하면 콜백에서 바로 액션 객체를 전달할 수 있습니까?
dispatch(()=>{res.data.msg, type:ERROR_MSG})
또는 이처럼 간단하게 발송할 수 있습니까? 'dispatch ({msg : res.data.msg, type : ERROR_MSG})' –
예. 방금 대답을 –
에 추가했습니다. 아무 것도 반환하지 않는 화살표 함수로 잘못 입력 한 부분을 OP에 표시했습니다. . –