Why is getInitialState not being called for my React class?

后端 未结 3 1228
无人共我
无人共我 2021-02-01 15:20

I\'m using ES6 classes with Babel. I have a React component that looks like this:

import { Component } from \'react\';

export default class MyReactComponent ext         


        
3条回答
  •  伪装坚强ぢ
    2021-02-01 15:54

    Code to accompany Nathans answer:

    import { Component } from 'react';
    
    export default class MyReactComponent extends Component {
      constructor(props) {
        super(props);
        this.state = {
          foo: true,
          bar: 'no'
        };
      }
    
      render() {
        return (
          
    {this.state.bar}
    ); } }

提交回复
热议问题