Skip to content

기능 실행시 새로고침 될 때, 에러는 안 나지만 서버로 데이터 전송이 안 되는 경우 #7

Description

@2myungho

container

onTest(){
 this.props.store.test();
 console.log("컨트롤러입니다.")
 window.location.reload();
}
**store**
async test(){
 console.log("스토어입니다.")
}

Console 출력
컨트롤러입니다.
스토어입니다.

컨트롤러에서 window.location.reload() 새로고침을 사용하게 되면 스토어 함수보다 새로고침이 더 빠르게 실행되기 때문에
서버로 데이터 전송이 안 될 때가 있다. (동작 시간은 비슷해서인지(?) 데이터 전송이 될 때가 더 많다.)

원하는 순서대로 함수를 실행해야 하기 때문에, 비동기 호출을 처리하는 .then을 사용했다.

container

onTest(){
 this.props.store.test( ).then(( ) => {
  console.log("컨트롤러입니다.");
  window.location.reload( );
  }
 );
}

이렇게 작성하게 되면
스토어입니다.
컨트롤러입니다.
새로고침.
순으로 실행이 됩니다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions