useState():

Key points :

Note: If you declare a state variable with the let keyword, you are able to update the state variable directly, but it won’t trigger a re-render.

export default function Test() {
  let [count, setCount] = useState(0);

  useEffect(() => {
    console.log("count1", count); //0
    count++;
    console.log("count2", count); //1
  }, []);

  return (
    <div>
      <h1>{count}</h1> //0
    </div>
  );
}

Note: If the component is re-rendered, the useState is invoked again, but this time it has its own updated state instead of the initializes with default state.

If you refresh the page, the state variables are set to the default state.