Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
how to make favorite list out of a random list of data react js

i have a random list of 10 dogs and fetching it from api https://dog.ceo/api/breeds/image/random/10 and with every refresh i get another 10 dogs list so my question is how do i make favorite list out of it and show it on another page. I dont want to use Localstorage or redux or context api.

DogHome.js

import "bootstrap/dist/css/bootstrap.min.css";
import "../../Pages/Pages.css";
import DogList from "../Dog/DogList";
import React, { Component } from "react";

class DogHome extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dogs: [],
    };
  }
  async componentDidMount() {
    try {
      const url = "https://dog.ceo/api/breeds/image/random/10";
      const response = await fetch(url);
      const data = await response.json();
      this.setState({ dogs: data.message });
    } catch (e) {
      console.error(e);
    }
  }

  render() {
    return (
      <div className="home">
        <DogList dogs={this.state.dogs} />
      </div>
    );
  }
}

export default DogHome;

DogList.js

import React from "react";
import Dog from "./Dog";
import "../../Pages/Pages.css";

const DogList = (props) => {
  const dogsArray = props.dogs.map((dogURL, index) => {
    return <Dog key={index} url={dogURL} />;
  });
  return (
    <>
      <div className="doglist">{dogsArray}</div>
    </>
  );
};

export default DogList;

and lastly here i have a favorite button in every dog image which i want to make favorite on click.

Dog.js

import React from "react";
import { Button } from "react-bootstrap";
import "../../Pages/Pages.css";

const Dog = (props) => {
  return (
    <div id="child">
      <img
        style={{ width: 300, height: 300 }}
        src={props.url}
        alt="ten dogs list"
      />
      <Button >Favorite</Button>
    </div>
  );
};

export default Dog;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You say don't want to use those APIs but you need a method to store favorites. How are you going to decide which are the favorites? How else are you planning to store the values of favorite dogs? You can use a database or a flat file. But you might as well take advantage of some of the React state management if that's your goal.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda