Created
August 31, 2020 18:50
-
-
Save marcelocmenezes/f4f3a418b8a510886e0377b3b98eff37 to your computer and use it in GitHub Desktop.
Aula React
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
import React, { useEffect } from "react"; | |
import { useState } from "react"; | |
function App() { | |
const [repositories, setRepositories] = useState([]); | |
useEffect(() => { | |
handleAddRepository(); | |
}, []); | |
async function handleAddRepository() { | |
await fetch("https://api.github.com/users/mocajatuba/repos") | |
.then((response) => response.json()) | |
.then((data) => setRepositories(data)); | |
} | |
function handleRemoveRepository(index) { | |
setRepositories(repositories.filter((item, i) => i !== index)); | |
} | |
return ( | |
<div> | |
<ul> | |
{repositories.map((repo, index) => ( | |
<li key={index}> | |
{repo.name} -{" "} | |
<button onClick={() => handleRemoveRepository(index)}> | |
Excluir | |
</button> | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment