Skip to content

Instantly share code, notes, and snippets.

View alexandrzavalii's full-sized avatar
🏠
Working from home

alex alexandrzavalii

🏠
Working from home
View GitHub Profile
class DumbosParent extends React.Component {
state = { availableShoes: 6 };
sellShoes = () => {
this.setState(({ availableShoes }, props) => ({
availableShoes: availableShoes > 1 && availableShoes - 1
}));
};
render() {
class Dumbo extends React.Component {
state = { clothing: null, firstChild: null, secondChild: null };
handleState = () => {
this.setState({
clothing: "jeans",
firstChild: "shoes",
secondChild: "hat"
});
};
render() {
// 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.`);
};
class Dumbo extends React.Component {
// static getDerivedStateFromProps(nextProps, prevState){ return prevState; }
state = { clothing : 'hat' };
// componentDidMount() { }
// shouldComponentUpdate() { }
// getSnapshotBeforeUpdate() { }
// componentWillUnmount() { }