Using axios.get() with React Native : In less than five minutes

npx react-native init chcuckNorisAPI
npm i axios
import React, { useEffect, useState } from 'react';import {Text, TouchableOpacity,Image,StyleSheet,View,StatusBar} from 'react-native';import Axios from 'axios'const App=()=>{const [details,setDetails] = useState(null)const url = ''const fetchData = async()=>{const {data} =await Axios.get(url)console.log(data);setDetails(data)}const handleClick=()=>{fetchData()}useEffect(()=>{fetchData()},[])return(<><View style={styles.conatiner}><Imagestyle={{width:150,height:150}}source= {{uri:details?.icon_url}}/><Text style={styles.text}>{details?.value}</Text><TouchableOpacity onPress={handleClick}><Text style={styles.button}>Load new Button</Text></TouchableOpacity></View></>)}export default App;const styles = StyleSheet.create({conatiner:{flex:1,justifyContent:'center',alignItems:'center'},button:{padding:15,color:"#FFFFFF",borderWidth:5,borderColor:"#FFFFFF",backgroundColor:'purple',borderRadius:50,alignSelf:'flex-end',marginVertical:15},text:{margin:10,color:"#000000",fontSize:15,fontWeight:'bold'}})
npx react-native start
npx react-native run-android (In another terminal)




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setting up a REST API using Express

Build Decoupled React Components with Inversion of Control

ES2021 — Logical Assignment Operator

Why React.js is my favorite?

Step №1.7 Creating Home Page in Application

The Future of Meta Tag Management for Modern React Development

Implementing CodePush in React Native

TC39 and its contributions to ECMAScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nilay Paul

Nilay Paul

More from Medium

Why I Like redux-observable

3 Ways How to Fix React Intl FORMAT_ERROR

How to fix “RNCSafeAreaProvider” was not found in the UIManager Error

Hookstate Performance: Subscribing to single items in a collection