简体   繁体   中英

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?

Same as React. You can just use fetch like this:

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:

  1. Axios
  2. Fetch API
  3. React Query
  4. RTK Query (Which I recommend especially if you'll be using redux in your app)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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