Skip to content

Instantly share code, notes, and snippets.

@yuval-a
Created January 31, 2019 17:56
Show Gist options
  • Save yuval-a/5f12b454985db7a212a55d12017c3162 to your computer and use it in GitHub Desktop.
Save yuval-a/5f12b454985db7a212a55d12017c3162 to your computer and use it in GitHub Desktop.
React Component class "abstract" prototype
import React, { Component } from 'react'
export default class ComponentName extends Component {
constructor(props) {
console.log ("constructor");
super(props);
this.state = {
};
}
componentDidMount() {
console.log ("Did mount");
}
componentDidUpdate(prevProps, prevState) {
console.log ("Did update");
}
shouldComponentUpdate(newprops) {
console.log ("Should update");
// return false to prevent calling render
return true;
}
componentWillUnmount() {
console.log ("Will unmount");
}
render() {
// return DOM as JSX, or null to render nothing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment