<script>
NPM
Magic CRA tool
import React from 'react'
/*{------ FUNCTIONAL COMPONENT -------}*/
/* { ---- ELEMENT ---- } */
const funComponent = () => <h1>Hello KITM fellas!</h1>
/*{------ CLASS COMPONENT -------}*/
class classComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
valueA: '',
}
}
render() {
/* { ---- ELEMENT ---- } */
return <h1>Hello KITM fellas!</h1>
}
}
/*{------ FUNCTIONAL COMPONENT -------}*/
class classComponent extends React.Component {
constructor() {}
componentDidMount() {}
componentDidUpdate() {}
componentWillUnmount() {}
// React ^16 Unsafe
componentWillReceiveProps() {}
componentWillUpdate() {}
componentWillMount() {}
// New
componentDidCatch() {}
static getDerivedStateFromProps() {}
getSnapshotBeforeUpdate() {}
}
Local State Change
Nothing Change
Local State Change
Nothing Change
Component Update
Local State Change
Nothing Change
Component Update
Diffing Algorithm
React implements a heuristic O(n) algorithm based on two assumptions:
https://reactjs.org/docs/reconciliation.html
<A>
<B aProps={ ...this.state } />
</A>
<B>
<C bProps={ ...props.aProps } />
</B>
<C>
<D cProps={ ...props.bProps } />
</C>
<D>
<E dProps={ ...props.cProps } />
</D>
<E>
{ this.props.dProps.user }
</E>
Avoid using index for key attribute
Use state management if and only if
your app is too big to handle by React