2017-12-15 1 views
0

상태가 생성자에 선언 된 기본 상태가되면 정의되지 않은 오류가 발생하는 이유는 무엇입니까?기본 상태가 null 또는 ''로 설정되어 있어도 정의되지 않은 this.state

constructor() { 
    super() 
    this.state = { 
     data: data, 
     q: null 
    } 
    } 

    filterC(o) { 
    if (this.state.q) { //wtf?? 
     return o['Id'].includes(this.state.q) 
    } 
    return o 
    } 

데모 : https://codesandbox.io/s/v35r8vyqwl 당신은 기능이 결합 할 필요가

+0

라고? –

+0

문제는이 바인딩과 관련이 있습니다.이 문제를 다양한 방식으로 처리하는 방법을 확인하십시오. https://stackoverflow.com/questions/47734862/why-reducer-does-not-respond-to-the-action/47740056#47740056 – ram1993

답변

0

:`filterC` 방법을

constructor(props) { 
    super(props) 
    this.state = { 
     data: data, 
     q: null 
    } 

    this.filterC = this.filterC.bind(this); 
    } 

    filterC(o) { 
    if (this.state.q) { 
     return o['Id'].includes(this.state.q) 
    } 
    return o 
    } 
관련 문제