It seems kind of magic to me how React is able to maintain the state variable value inside the functional component between re-renders. So I tried to implem