Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

useEffect hook

import {useEffect, useState} from 'react';

export default function App() {
  const [counter, setCounter] = useState(0);


  // ✅ hook is called at top level (not conditionally)
  useEffect(() => {
    if (counter > 0) {
      console.log('hello world');
    }
  });

  return (
    <div>
      <button onClick={() => setCounter(counter + 1)}>toggle loading</button>
      <h1>Hello world</h1>
    </div>
  );
}
Source by bobbyhadz.com #
 
PREVIOUS NEXT
Tagged: #useEffect #hook
ADD COMMENT
Topic
Name
9+5 =