React
async, await
hmk run dev
2021. 5. 20. 16:41
async, await 비동기 처리할 때 필요한 친구다...
함수가 특정 함수가 실행된 후에 다른 함수를 실행시키고 싶을 때 아래처럼 써주면 된다!
아래 코드는 각각 유저의 마이페이지를 옮겨 다닐떄 (나의 페이지 >> 다른 유저 페이지 or 다른 유저 페이지 >> 다른 유저의 페이지)
원래 있던 데이터를 초기화 시켜주고 새로운 데이터를 넣어주기 위해 비동기 처리를 해주었던 코드이다
const initializeApp = async () => {
await dispatch(profileActions.resetProfile([]));
await dispatch(storyPostActions.resetStory([]));
dispatch(profileActions.getUserInfoAPI(userId));
dispatch(storyPostActions.getUserPostAPI(userId));
dispatch(storyPostActions.getUserLikeAPI(userId));
};