Last active
August 17, 2018 00:28
-
-
Save phongvh/258d07330c76dbefb9671301d1b9bd6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pseudo code | |
class Component { | |
let state = {} // private | |
var props = {} | |
var propTypes = {} | |
var contextTypes = {} | |
// Methods | |
constructor(props, context, updater){ | |
this.props = props | |
} | |
setState = (newState) => { | |
this.state = Object.assign({}, state, newState) | |
} | |
forceUpdate = (callback) => {} | |
getInitialState = () => {} | |
getDefaultProps = () => {} | |
// Life cycle | |
// Called before component will be mounted | |
componentWillMount = () => {} | |
// Called after component was mounted | |
componentDidMount = () => {} | |
// Called when a prop is assigned new value | |
componentWillReceiveProps = (nextProps) => {} | |
// If returned true, component will be re-render; if false, component will not be re-render | |
shouldComponentUpdate = (nextProps, nextState, nextContext) => {} | |
// Called before component will be updated | |
componentWillUpdate = (nextProps, nextState, nextContext) => {} | |
// Called after component was updated | |
componentDidUpdate = (nextProps, nextState, nextContext) => {} | |
// Called before component will be unmounted | |
componentWillUnmount = () => {} | |
updateComponent = () => {} | |
// Render | |
render = () => {} | |
} | |
// Use | |
class Example extends Component { | |
state = {newDefaultState: true} | |
props = {newDefaultProps: true} | |
constructor(props) { | |
this.newActionNeedBind = this.newActionNeedBind.bind(this); | |
} | |
componentDidMount() {newAction()} | |
componentWillReceiveProps(nextProps) {newAction()} | |
componentDidUpdate() {newAction()} | |
componentWillUnmount() {newAction()} | |
// TODO: add more life cycle function | |
newAction = () => {} | |
newActionNeedBind() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment