/porto

Primary LanguageCSS

React on Heroku experiment

Resources

tl;dr

  1. Always call super() if you have a constructor and don't worry about it if you don't have a constructor
  2. Call super(props) only if you want to access this.props inside the constructor. React automatically set it for you if you want to access it anywhere else.

tl;dr

  • ES5 vs ES6
  1. extend from React.Component
  2. use constructor to initialize state
  3. specifiy proptypes as a method on the component

Best Practices

DON'T bind with constructor

class HelpSearch extends Component {
  constructor() {
    super();
    this.completeSearch = this.completeSearch.bind(this);
  }

  completeSearch() {
    ...
  }
}

DO bind with fat-arrow

class HelpSearch extends Component {
  constructor() {
    super();
  }

  completeSearch = () => {
    ...
  }
}

Autobinding

Modules

Fetch

fetch

The global fetch function is an easier way to make web requests and handle responses than using an XMLHttpRequest. This polyfill is written as closely as possible to the standard Fetch specification at https://fetch.spec.whatwg.org.