Created
June 1, 2019 07:49
-
-
Save ivan-ha/263efa56ad22d0ec10fdbdc39c425a2e to your computer and use it in GitHub Desktop.
react-hooks-test-using-hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const App = () => { | |
| const [users, setUsers] = useState([]); | |
| useEffect(() => { | |
| (async () => { | |
| try { | |
| const response = await axios( | |
| "https://randomuser.me/api/?results=10&inc=name,login&nat=us" | |
| ); | |
| setUsers(response.data.results); | |
| } catch (error) { | |
| console.error(error); | |
| } | |
| })(); | |
| }, []); | |
| return ( | |
| <ol> | |
| {users && | |
| users.map(({ name, login }) => ( | |
| <li key={login.uuid}> | |
| {`${name.title} ${name.first} ${name.last}`} | |
| </li> | |
| ))} | |
| </ol> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment