Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // npm install axios --save
- import { useEffect, useState } from 'react';
- import './App.css';
- import axios from "axios";
- function App() {
- const [user, setUser] = useState([]);
- const fetchData = () => {
- return axios.get("http://domain.com/api/v1/users")
- .then((response) => setUser(response.data));
- }
- useEffect(() => {
- fetchData();
- },[])
- return (
- <main>
- <div className='container'>
- <h1>Users</h1>
- <ul>
- {user && user.length > 0 && user.map((userObj, index) => (
- <li key={userObj._id}>{userObj.nya}</li>
- ))}
- </ul>
- </div>
- </main>
- );
- }
- export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement