action.js비동기/대기중인 툰크 작업 방법
export function getLoginStatus() {
return async(dispatch) => {
let token = await getOAuthToken();
let success = await verifyToken(token);
if (success == true) {
dispatch(loginStatus(success));
} else {
console.log("Success: False");
console.log("Token mismatch");
}
return success;
}
}
component.js
그러나componentDidMount() {
this.props.dispatch(splashAction.getLoginStatus())
.then((success) => {
if (success == true) {
Actions.counter()
} else {
console.log("Login not successfull");
}
});
}
, 내가 비동기로 component.js 코드를 작성할 때/나는이 오류를 얻을 아래처럼 기다리고 :
Possible Unhandled Promise Rejection (id: 0): undefined is not a function (evaluating 'this.props.dispatch(splashAction.getLoginStatus())')
component.js
async componentDidMount() {
let success = await this.props.dispatch(splashAction.getLoginStatus());
if (success == true) {
Actions.counter()
} else {
console.log("Login not successfull");
}
}
어떻게 getLoginStatus()를 기다리고 나머지 명령문을 실행합니까? .then()를 사용하면 모든 것이 잘 작동합니다. 내 비동기/기다리는 구현에 뭔가 빠져 있음을 의심합니다. 그걸 알아 내려고 했어.
혹시이 패턴을 해결 했습니까? 그렇다면 여기에 답변을 게시 할 수 있습니까? – ajonno
왜 당신은 redux connected react 구성 요소에서 약속을 기다리고 있습니까? 이것은 데이터 유니 방향 패턴을 깨고 있습니다. – Aaron