Flow (React Native) is giving me errors for using 'this.state'

后端 未结 4 1649
死守一世寂寞
死守一世寂寞 2021-01-01 08:34

Flow is giving me the following error whenever I try to use this.state in my code:

object literal: This type is incompatible with un

4条回答
  •  温柔的废话
    2021-01-01 09:21

    You need to define a type for the state property in order to use it.

    class ComponentA extends Component {
        state: {
            isExpanded: Boolean
        };
        constructor(props) {
            super(props);
            this.state = {
                isExpanded: false
            };
        }
    }
    

提交回复
热议问题