Relative Content

Tag Archive for react-hooks

Usestate hook not working on nextjs

i have build my own state on next js but the usestate hook didn’t work I had already install latest version of next js & react also use “use client”

use effect function is not working as expected

import React,{useState,useEffect} from ‘react’ function Counter() { const [count,setCount] = useState(0) const incCount=()=>{ console.log(“count “,count) // setCount(count+1) setCount(x=>x+1) } useEffect(()=>{ console.log(‘use effect called’) const intervalId = setInterval(()=> incCount(),1000) return()=>{ // clearInterval(intervalId); console.log(“clear interval called”) } },[]) return ( <div> {count} </div> ) } export default Counter In display count is increasing as expected but in […]