I am using reactjs in my application . The currid_s is set to value -1 initially.. later after button click it is set to 2 but the timer doesnot show the updated value in the Console. Why? Here is the code
import React, { useState, useEffect } from "react";
export default function App() {
const [currid_s, setcurrid_s] = React.useState(-1);
const handless = () => {
console.log("yess");
setcurrid_s(2);
};
useEffect(() => {
console.log(currid_s, "yes");
getPosts();
const interval = setInterval(() => {
getPosts();
}, 2000);
return () => clearInterval(interval);
}, []);
// const all_pooo=()=>{
// console.log(curr,"dddd")
// }
const getPosts = async () => {
console.log(currid_s);
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<button onClick={handless}>gggg</button>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
Here is the link to code sandbox https://codesandbox.io/embed/beautiful-ardinghelli-dg1r4?file=/src/App.js&codemirror=1