Get data with React js : axios

rjs-axios


In this guide, you will see exactly how to use Axios.js with React using tons of real-world examples featuring React hooks.

You'll see why you should use Axios as a data fetching library, how to set it up with React, and perform every type of HTTP request with it.

Then we'll touch on more advanced features like creating an Axios instance for reusability, using async-await with Axios for simplicity, and how to use Axios as a custom hook.

import React, { useEffect } from 'react';
import axios from 'axios';

    function App() {

      useEffect(()=>{
        axios.get("https://jsonplaceholder.typicode.com/todos/")
        .then(response=>console.log(response.data))
       },[])

      return (
        <div>
         

        </div>
      );
    }

    export default App;
get data into document, with Key Properties..

import React, { useEffect, useState } from 'react';
import axios from 'axios';

    function App() {
      var [data,setData] = useState([]);

      useEffect(()=>{
        axios.get("https://jsonplaceholder.typicode.com/todos/")
        .then(response=>
          // console.log(response.data)
          setData(response.data)
          )
       },[])

      return (
        <div>
         
         {
          data.map ((item) => <li key={item.id}>{item.title}</li>)
         }

        </div>
      );
    }

    export default App;