An open API service indexing awesome lists of open source software.

https://github.com/opensource-direct/react-native-axios

React Native Axios Consume API by HTTP Protocol
https://github.com/opensource-direct/react-native-axios

api axios http react-native

Last synced: about 1 year ago
JSON representation

React Native Axios Consume API by HTTP Protocol

Awesome Lists containing this project

README

          

## react-native-axios
React Native Axios Consume API by HTTP Protocol

## Get Data News API in Console Log
Untuk fetch data dari API kita Perlu Menginstallkan `Axios`

```shell
~/Desktop/react-native/ReactNativeAxios ⌚ 11:50:48
$ npm install axios
```

Screen Shot 2023-03-29 at 12 43 47

kemudian pada App.tsx rename menjadi App.js, lalu ubah isinya seperti tampak pada kodingan dibawah ini

```js
import { StyleSheet, Text, View } from 'react-native'
import React, { useEffect } from 'react'
import axios from 'axios'

export default function App() {
console.info('Ini coba ambil data');

const getData = async () => {
try {
const res = await axios.get('https://newsapi.org/v2/top-headlines', {
params: {
country: 'id',
category: 'technology',
apiKey: '87d43d69278f492783fddbd07988ad8b'
}
})

console.info('Get Data New : ', res)
} catch (error) {
console.error(error.message)
}
};

useEffect(() => {
getData()
}, [])

return (

App

)
}

const styles = StyleSheet.create({})
```

running kemudian coba debug aplikasi, akses log pada `React Native Debugger` inspect element kemudian arahkan ke bagian `console`

Screen Shot 2023-03-29 at 12 46 10

Preferensi Library yang Diinstallkan

- [x] https://www.npmjs.com/package/axios