2017-11-03 8 views
1

loading = true (networkStatus = 1)에서 쿼리가 중단 될 수있는 이유는 무엇입니까?<query>.로드가 true로 변경되지 않습니다.

나는 다시 반입에 대한 쿼리의 결과를 얻을 수없고 'called2'

graphql(_stepQuery, { 
    name: 'stepQuery', 
    options: ({goalDocId}) => ({ 
     fetchPolicy: 'network-only', 
     notifyOnNetworkStatusChange: true, 
     variables: { 
     goalDocId 
     } 
    }) 
    } 
) 

componentWillReceiveProps(nextProps) { 
    let stepIdsFromServer 
    if (nextProps.currentGoalSteps.length > this.props.currentGoalSteps.length) { 
     console.log('called') 
     this.props.stepQuery.refetch() 
     console.log('this.props', this.props) 
     console.log('nextProps',nextProps) 
     if (!nextProps.stepQuery.loading) { 
     // console.log('nextProps.stepQuery.allSteps', nextProps.stepQuery.allSteps) 
      console.log('called2') 
} 

답변

1

이것은 무한 루프에 매우 위험한 모습을 로그인 할 수 없습니다.

먼저 refetch 함수는 Promise이므로 다시 가져 오기를 호출 한 직후 정확한 쿼리 상태를 알 수 없습니다. .then 기능을 사용해야합니다. refetch Api을 참조하십시오.

두 번째 쿼리는 graphql 래퍼 구성 요소 내에서 실행됩니다. 따라서 로딩 상태를 확인하고 componentWillReceiveProps 함수로 다시 가져 오면 안됩니다. 쿼리가 다시 실행될 때 전체 구성 요소가 다시 인스턴스화되고 재설정 상태와 함께 componentWillReceiveProps 함수가 입력되기 때문에 그렇게해야합니다.

어떤 종류의 검색이 필요한 경우 해결 방법으로 withApollo 래퍼를 사용하고 componentWillReceiveProps에서 this.props.client ("MUTATION")을 호출하면 변형 전체를 렌더링하지 않기 때문에 사용하는 것이 좋습니다. 구성 요소.