【问题标题】:REACT- I want to send an API get request every time i refresh the page (F5)反应 - 我想在每次刷新页面时发送一个 API 获取请求 (F5)
【发布时间】:2022-11-19 21:14:42
【问题描述】:

我正在构建一个带有 REACT 和 expressJS 服务器的数独应用程序。 我希望板子在每次刷新页面时加载上次保存的板子,这样用户就不会丢失数据。

iv managed to send a post request to the seerver and send the current board, I store the current board in an array (at the server) and i manage to update it every POST request so that everytime a change is accuring withing the board im 发送了一个post请求,效果很好,数据也被存储了。

我尝试使用“useeffect”,所以当我加载页面时,客户端将向服务器发送一个获取请求并获取最后存储的板的数组。 问题是当我加载页面时它会执行一次,但当我刷新页面时它不起作用。 (F5)。

我希望能够在每次刷新页面时发送一次获取请求。

【问题讨论】:

    标签: reactjs api react-hooks server get


    【解决方案1】:

    检查此问题是否可以通过使用 localstorage 来保存数据来提供帮助 https://stackoverflow.com/a/45069792/8808725

    【讨论】:

      猜你喜欢
      • 2021-03-16
      • 2018-10-06
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2015-07-09
      • 2020-05-25
      • 2017-12-01
      相关资源
      最近更新 更多