ReactJS this.state null

前端 未结 5 1241
谎友^
谎友^ 2020-12-28 11:31

Let me preface this by saying I am a novice to ReactJS. I am trying to learn by making a simple site that populates data using React. I have a JSON file that contains link d

5条回答
  •  清酒与你
    2020-12-28 12:21

    More actual answer, for using ES7+ Classes:

    export class Counter extends React.Component {
      state = { data : [] };
      ...
    }
    

    ES6 Classes (alredy was answered)

    export class Component extends React.Component {
      constructor(props) {
        super(props);
        this.state = { data : [] };
      }
      ...
    }
    

提交回复
热议问题