Last active
April 12, 2022 07:31
-
-
Save renton4code/8c4a060c75538d82204256ebbea5190f to your computer and use it in GitHub Desktop.
React class vs hooks
This file contains hidden or 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 Example extends React.Component { | |
contructor(props) { | |
super(props); | |
} | |
componentDidMount() { | |
console.log("component has been mounted"); | |
} | |
componentDidUpdate() { | |
console.log("component has been updated"); | |
} | |
componentWillUnmount() { | |
console.log("component is about to unmount"); | |
} | |
} | |
const Example = (props) => { | |
React.useEffect(() => { | |
console.log("component has been mounted"); | |
return () => { | |
console.log("component is about to unmount"); | |
}; | |
}); | |
React.useEffect(() => { | |
console.log("component has been updated"); | |
}, [props]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment