2017-12-08 5 views
0

구성 요소를 만들고 있는데 componentDidUpdate 메서드를 사용해야합니다. 안에는 이걸 사용하고 있습니다. 문제는 this.props 사용에 오류가 발생합니다. 그것은 속성 소품이 클래스에 존재하지 않는다고 말합니다.this.props에서 flow가 오류를 발생시킵니다. componentDidUpdate 메서드를 사용합니다.

props: Props 

을하지만이 작동하지 않습니다 :

지금은 같은 것을 할 수 있습니다. 이제는 componentDidUpdate 메소드 내부에서 this.props의 타입이 "mixed"가됩니다.

type Props = { 
    show: boolean, 
    text: string 
} 
export default ConfirmBox extends Component<Props> { 
    // props: Props; 
    componentDidUpdate() { 
    if(this.props.show) { 
     // some logic 
    } else { 
     // some other logic 
    } 
    } 
    . 
    . 
    . 
} 

나 좀 도와주십시오

내 클래스는이 같은 것입니다. React 구성 요소에서 흐름을 사용하면 많은 혼란과 고통을 초래합니다.

답변

-1

구성 요소 자체가 제대로 구성되지 않은 경우 ... 아마도이 같은 접근 시도로 느낀다 :

import React from 'react'; 
import PropTypes from 'prop-types'; 

export default class FooComponent extends React.PureComponent { 
    componentDidUpdate() { 
    console.log(this.props); 
    } 

    render() { 
    return (
     <h1>Foo</h1> 
    ); 
    } 
} 

FooComponent.propTypes = { 
    text: PropTypes.string.isRequired, 
}; 
관련 문제