Skip to content

Instantly share code, notes, and snippets.

@szaranger
Last active November 6, 2021 22:36
Show Gist options
  • Save szaranger/a0b0f22710e19867e0bede94899358c7 to your computer and use it in GitHub Desktop.
Save szaranger/a0b0f22710e19867e0bede94899358c7 to your computer and use it in GitHub Desktop.
import React, { useEffect } from 'react';
function MyComponent() {
useEffect(() => {
// Run once after DOMContentEvent loads
}, []);
useEffect(() => {
// Synchronize the state with the state of this component.
return function cleanup() {
// Cleanup the previous side-effect before running a new one
}
// Run the side-effect and it's cleanup to for the re-run
}, [a, b ,c, d]); // When any of these change
useEffect(() => {
// Run every single time this component is re-rendered
});
return {
// Render React elements
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment