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

148
Vistas
React component changing other component state when I try to set a file to it. How could I fix it?

I have a react component with a state that holds file source, file URL, and some other values that come from text fields in that same component. When I render that component multiple times and try to set a file to them, it works fine for the first one, but when I try to set a file on the second or third, etc. components, it sets that file to the first one only (first component state). The state is not shared, not pulled down from the parent component. When I try to change the text in the text fields, it works fine, the text appears where it should on all of them. Any ideas what is wrong with this, and how could I fix this problem? Thanks in advance.

Component state and state handlers code:

const [value, setValue] = useState({
    fileSrc: null,
    fileURL: '',
    name: '',
    desc: '',
    price: 0,
});

const handleFile = (e) => {
    setValue({
        ...value,
        fileSrc: e.target.files[0],
        fileURL: URL.createObjectURL(e.target.files[0])
    });
};

const handleValueChange = (prop) => (event) => {
    setValue({ ...value, [prop]: event.target.value });
};
about 4 years ago · Juan Pablo Isaza
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