简体   繁体   English

如果我们使用 nodejs 和 mysql 创建后端,如何在 react native 中获取数据

[英]How to fetch data in react native if we created backend with nodejs and mysql

So i am very new to react native, but i got little bit understanding in react node express and mysql.let's just say i created backend with node js, express and mysql so how we fetch the data from react native, is it same way like what we do in react?所以我对 React Native 很陌生,但我对 React Node Express 和 mysql 了解不多。假设我用 Node JS、Express 和 MySQL 创建了后端,那么我们如何从 React Native 获取数据,是不是像我们做什么反应?

Same as React.与 React 相同。 You can just use fetch like this:您可以像这样使用 fetch :

import {useEffect} from "react";
const fetchData = () => {
return fetch("...")
 .then((response) => response.json())
 .then((data) => console.log(data));}
 
useEffect(() => {
 fetchData();
 }, []);

Yes, it is the exact same way you'd do it with React, so you most commonly will have 4 options:是的,这和你用 React 做的完全一样,所以你通常会有 4 个选择:

  1. Axios公理
  2. Fetch API 获取API
  3. React Query反应查询
  4. RTK Query (Which I recommend especially if you'll be using redux in your app) RTK 查询(如果你将在你的应用程序中使用 redux,我特别推荐)

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

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