React钩子--POST调用Node JS被反复调用并刷新状态。如何只发布一次数据?

问题描述 投票:0回答:1

我试图实现对Node JS的POST调用,但是在得到响应后,它又在不断地调用。由于这个原因,状态正在刷新。我是React的新手,请给予建议。

axios({
  method: 'post',
  url: '/api/project/create',
  headers: {
    "Accept": "application/json",
    'content-type': 'application/json'
  },
  data: data
})
.then(response => {
  setResCode({resCode: response.statusCode}) // Due to this line, my axios is starts calling again and again
})
reactjs post react-hooks state
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.