Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

setstate callback in functional component code example

Example: react functional components setstate callback

const [state, setState] = useState({ name: "Michael" })
const isFirstRender = useRef(true)

useEffect(() => {
  if (!isFirstRender.current) {
    console.log(state) // do something after state has updated
  }
}, [state])

useEffect(() => { 
  isFirstRender.current = false // toggle flag after first render/mounting
}, [])

Tags:

Misc Example

Related

how to convert put route in post route code example default line height in html code example bootstrap tooltip override by jquery ui tooltops code example add multiple class using javascript code example docker save image from running container code example laravel eloquent delete all code example check for updates in git bash code example chromium python webdriver ubutnu code example handling select in selenium code example mui button with text and icon code example find js regex code example FasterXML jackson json java code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy