当我在 React 中重新加载我的页面时,我在 useState 中的数据丢失了

My data in useState gets lost when i reload my page in react

const [credentials, setCredentials] = useState({name:"", password:""});

如果你想保留一些状态,你最好使用像本地存储这样的机制。

相关阅读:Using localStorage with React Hooks