简体   繁体   English

使用 fetch 和生命周期组件的 react web 示例代码在哪里

[英]Where is react web example code using fetch and life cycle components

I'm making web using react.我正在使用 react 制作网络。

Most of my react code is from airbnb style ( https://github.com/airbnb/react-dates )我的大部分反应代码来自 airbnb 风格( https://github.com/airbnb/react-dates

but I can't find How to use Fetch API in react web.但我找不到如何在 react web 中使用 Fetch API。

can you recommend a good example?你能推荐一个很好的例子吗?

You can look at this article https://daveceddia.com/ajax-requests-in-react/你可以看看这篇文章https://daveceddia.com/ajax-requests-in-react/

It uses axios but you can follow the same pattern and replace the axios code with它使用axios但您可以遵循相同的模式并将axios代码替换为

fetch('http://api.exampledomain.com/api/search')
.then((response) => response.json())
.then((jsonData) => {
  //handle json data processing here
  console.log(jsonData);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM