import React, { useEffect, useState } from "react";
import "./App.css";
function App() {
const [data, setData] = useState({ count: 1 });
const handleClick = () => {
let temp = data;
data.count += 1;
console.log("temp: ", temp); // temp: {count: 2}
setData(temp);
console.log(data); //{count: 2}
};
React.useEffect(() => {
console.log("hello");
}, [data]);
return (
<div className="App">
{data.count}
<button onClick={handleClick}>add</button>
</div>
);
}
export default App;
the state is changing but in the UI display data is not updating. i don't know why? like if I click on the add button the state is changing from
data = {count: 1} to data = {count: 2}
but in the ui display the data remain 1. it is not updating in the ui. so what to do?