Advertisement
zidniryi

App.js

Oct 25th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useState, useEffect } from "react";
  2.  
  3. import axios from "axios";
  4.  
  5. function App() {
  6.   const [dataXML, setdata] = useState({});
  7.  
  8.   const getData = async () => {
  9.     try {
  10.       const response = await axios.get(
  11.         "http://api.nbp.pl/api/exchangerates/tables/a",
  12.  
  13.         {
  14.           "Content-Type": "application/xml; charset=utf-8",
  15.         }
  16.       );
  17.  
  18.       setdata(response.data[0]);
  19.     } catch (error) {
  20.       console.log(error);
  21.     }
  22.   };
  23.  
  24.   useEffect(() => {
  25.     getData();
  26.   }, []);
  27.  
  28.   console.log(dataXML);
  29.  
  30.   return (
  31.     <div>
  32.       <h1>{dataXML.effectiveDate}</h1>
  33.  
  34.       <h2>{dataXML.no}</h2>
  35.     </div>
  36.   );
  37. }
  38.  
  39. export default App;
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement