View on GitHub

marymafa.github.io


layou: post title: Axios date: 2018-03-27 —

Axios

Is a lightweight http client basede on the $http service within Angular.s v1.x and similar to the Fetch API. Axios allows you to define a base instance in which you can define a URL and any other configuration elements. The XMLHttpRequest API is built in to React Native.

axios.get

is an asynchronous function which means that the rest of the code will be executed .And when the response of the server arrives, the function passed to then will be executed. The return value of axios.get(‘url’) is called a promise object.

React Native

Actually translates your markup to real, native UI elements, leveraging existing means of rendering views on whatever platform you are working with. Additionally, React works separately from the main UI thread, so your application can maintain high performance without sacrificing capability. The update cycle in React Native is the same as in React: when props or state change, React Native re- renders the views. The major difference between React Native and React in the browser is that React Native does this by leveraging the UI libraries of its host platform, rather than using HTML and CSS markup.

By using axios you can cut out the middle step of passing the results of the http request to the .json() method. Axios just returns the data object you would expect.