Skip to content

Instantly share code, notes, and snippets.

@berkelmas
Created July 25, 2020 17:45
Show Gist options
  • Save berkelmas/3fe907c685be8c495c83b25e8439df5e to your computer and use it in GitHub Desktop.
Save berkelmas/3fe907c685be8c495c83b25e8439df5e to your computer and use it in GitHub Desktop.
import React, {useEffect, useState} from "react";
const ExampleUseEffect = props => {
const [exampleState, setExampleState] = useState({name: "Berk"})
useEffect(() => {
console.log("I execute in component's first render.")
}, []);
useEffect(() => {
console.log("I execute when exampleState state changes.");
}, [exampleState])
useEffect(() => {
console.log("I execute when props changes.")
}, [props])
useEffect(() => {
console.log("I execute every single render of my component.")
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment