0
두 블록의 비동기 작업을 수행하여 다음 코드 블록을 사용하기 전에 제대로 실행되었는지 확인해야합니다. 메소드 createSession()과는 createUser()는 첫 번째와 두 번째까지 내가 조금 "대기"하는 방법에 대해 잃었어요 비동기 작업이컨테이너 구성 요소에서 비동기 작업을 처리하는 가장 좋은 방법
createUser =() => {
let user = this.state.user
//create user session (this is a async action - thunk)
//What is the correct way to wait until this method is executed?
this.props.createSession(user)
//if session exists means it was created
if(this.props.session.session) {
//What is the correct way to wait until this method is executed?
this.props.createUser(user) //another async action
if(this.props.userReducer.currentUser) {
ToastAndroid.show('User registered successfully!', ToastAndroid.SHORT)
this.props.goTo('productsContainer') //transition to the next scene
}
} else {
ToastAndroid.show(this.props.session.err, ToastAndroid.SHORT)
}
}
때문에 :
코드는 다음과 같습니다 하나가 실행됩니다.
어쩌면 그것은 바보 같은 질문이지만 나는 반응을 줄이는 세계에서 초보자입니다.