Skip to content

Instantly share code, notes, and snippets.

@renton4code
Last active April 12, 2022 07:31
Show Gist options
  • Save renton4code/8c4a060c75538d82204256ebbea5190f to your computer and use it in GitHub Desktop.
Save renton4code/8c4a060c75538d82204256ebbea5190f to your computer and use it in GitHub Desktop.
React class vs hooks
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