简体   繁体   中英

How to fetch data from API in React Native

I am trying to fetch data from API on my localhost server using "Axios" in React Native but I am stuck that how can i do This is my react code that same i have to convert in react native

export function blog(props){
const posts = useAPI ('/api/posts');
return (
<ul>
{posts?.data && 
posts.data.map((post) => (
<li>
{posts.name}
</li>
))
}
);
}

export default blog;

You have to make a proper API endpoint

like your localhost
localhost:8080/api/posts then you have use like this
1: Know your IP address (192.168.1.1)

you can get IP address in cmd in windows: ipconfig
you can get IP address in System Preference/Networ/Selected Network / Info in mac

2: Your endpoint will be look like this
http://192.168.1.1/api/posts

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