marp | theme |
---|---|
true |
ctheme |
function Welcome(props) {
return <h1>Hello, {this.props.name}</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
The only method you must define in a React.Component subclass is called
render()
. All the other methods are optional.
class Header extends React.Component {
constructor(props) {
super(props);
// this.state = {favoritecolor: "red"};
}
static getDerivedStateFromProps(props, state) {
// return {favoritecolor: props.favcol };
}
componentDidMount() {
// this.setState({favoritecolor: "yellow"})
}
shouldComponentUpdate(nextProps, nextState) {
// return nextState.favoritecolor !== this.state.favoritecolor;
}
getSnapshotBeforeUpdate(prevProps, prevState) {
//
}
componentDidUpdate(prevProps, prevState, snapshot) {
// if (this.props.userID !== prevProps.userID) {
// this.fetchData(this.props.userID);
// }
}
componentWillUnmount() {
// alert("The component named Header is about to be unmounted.");
}
render() {
return (
<h1>My Favorite Color is {this.state.favoritecolor}</h1>
);
}
}
Mount phase:
constructor()
static getDerivedStateFromProps()
render()
componentDidMount()
Update phase:
static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
Unmount phase:
componentWillUnmount()
Error handling
static getDerivedStateFromError()
componentDidCatch()
<style scoped>ul li { font-size: 0.8rem; }</style>