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
class DumbosParent extends React.Component { | |
state = { availableShoes: 6 }; | |
sellShoes = () => { | |
this.setState(({ availableShoes }, props) => ({ | |
availableShoes: availableShoes > 1 && availableShoes - 1 | |
})); | |
}; | |
render() { |
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
class Dumbo extends React.Component { | |
state = { clothing: null, firstChild: null, secondChild: null }; | |
handleState = () => { | |
this.setState({ | |
clothing: "jeans", | |
firstChild: "shoes", | |
secondChild: "hat" | |
}); | |
}; | |
render() { |
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
// JSX | |
const Dumbo = props => { | |
return <div>Hey, my name is Dumbo.</div>; | |
}; | |
// without JSX | |
const Dumbo = props => { | |
return React.createElement("div", null, `Hey, my name is Dumbo.`); | |
}; |
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
class Dumbo extends React.Component { | |
// static getDerivedStateFromProps(nextProps, prevState){ return prevState; } | |
state = { clothing : 'hat' }; | |
// componentDidMount() { } | |
// shouldComponentUpdate() { } | |
// getSnapshotBeforeUpdate() { } | |
// componentWillUnmount() { } | |
NewerOlder