tl;dr
- Always call super() if you have a constructor and don't worry about it if you don't have a constructor
- 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
- extend from React.Component
- use
constructor
to initialize state- specifiy
proptypes
as a method on the component
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 = () => {
...
}
}
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.