Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

useeffect hook react

import React, { useState, useEffect } from 'react'

export default function App() {
  const [count, setCount] = useState(0)
  const color = count % 5 === 0 ? 'red' : 'blue'

  useEffect(() => {
    document.body.style.backgroundColor = color
  }, [color])

  return (
    <button
      onClick={() => {
        setCount(count + 1)
      }}
    >
      Click HERE to increment: {count}
    </button>
  )
}
Source by www.react.express #
 
PREVIOUS NEXT
Tagged: #useeffect #hook #react
ADD COMMENT
Topic
Name
9+6 =