diff --git a/src/components/getCharacters.tsx b/src/components/getCharacters.tsx index 5e40ba8..8cfad49 100644 --- a/src/components/getCharacters.tsx +++ b/src/components/getCharacters.tsx @@ -5,9 +5,8 @@ import notfound from "../images/not-found.png"; const GetCharacter: React.FC = () => { const [character, setCharacter] = useState>([]); - + const [favorite, setFavorite] = useState>([]); const [searchName, setSearchName] = useState(""); - const [search, setSearch] = useState(false); const [loading, setLoading] = useState(true); @@ -16,6 +15,23 @@ const GetCharacter: React.FC = () => { setSearchName(searchName); }; + useEffect(() => { + localStorage.setItem("favorite", JSON.stringify(favorite)); + }, [favorite]); + + const newFavorite = () => { + Service.getAll() + .then((response) => { + const favoritos = response.data.results; + console.log(favoritos); + const salvar = JSON.stringify(favoritos); + localStorage.setItem("favoritos", salvar); + }) + .catch((e) => { + console.log(e); + }); + }; + useEffect(() => { retrieveCharacter(); }, []); @@ -120,6 +136,7 @@ const GetCharacter: React.FC = () => { marginTop: -15, marginLeft: 10, }} + onClick={newFavorite} >