2017-10-24 10 views

답변

0

는 여기있다 :

this.setState 그것은 때 구성 요소 않은 마운트하여 간격을 취소 할 수 있는지 확인하는 것이 중요합니다 귀하의 질문에

setInterval(() => { 
    call.to.api(data => { 
     this.setState({graphql_data}); 
     // this will update your ui, as soon as state is set 
    }) 
},miliseconds) 
2

의 열쇠입니다. 그렇지 않으면 "마운트 해제 된"구성 요소에서 상태를 설정하는 방법을 설명하는 오류 메시지 세트로 끝납니다.

import React, { Component } from 'react' 

class Carousel extends Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      intervalId = 0, 
      updatedProps: {} 
     } 
    } 
    componentDidMount() { 
     let self = this; 
     let id = setInterval(function() { 
      // GRAPHQL => data 
      this.setState({updatedProps: data, intervalId: id}) 
     }) 
    } 
    componentWillUnMount() { 
     clearInterval(this.state.intervalId) 
    } 
    render() { 
     return (
      <div> 
       <Carousel 
        props={this.state.updatedProps} 
       /> 
      </div> 
     ) 
    } 
} 
+0

Nice One ... !!! –