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

156
Vistas
updating state correctly oncompleted query from apollo

so im trying to update an state for each individual case

{buyer.map((x) => {
        return <IdentificationCard id={x.id} />;
     })}

(inside identificationCard component)
const [uploadFile, { data, error }] = useMutation(UPLOAD_ALL_DOCUMENTS, {
  onCompleted({ uploadFile }) {
        const cardFrontDownloadLink = uploadFile.contract.buyer.documents.id_anverse_download_link;
        const cardBackDownloadLink = uploadFile.contract.buyer.documentss.id_reverse_download_link;   
        setFormValues({
           ...formValues,
           buyerData: {
              ...formValues.buyerData,
              buyer: buyer.map((x) => {
                 return x.id == id
                    ? {
                         ...x,
                         idCardFront: cardFrontDownloadLink ? cardFrontDownloadLink : '' ,
                         idCardBack: cardBackDownloadLink ? cardBackDownloadLink : ''
                      }
                    : x
              })
           }
        });
  },
  onError({ imgError }) {
     notification.error({
        message: 'Error',
        description: 'try loading your ID again or check your internet connection'
     });
  }

});

for example, When i drop an image onto the idCardFront, this query returns a link, and then i update the buyer object key with the link as its new value, however heres is my problem, after updating that first state, i try to do the same with the idCardBack on the second mapped IdentificationCard component, and it updates de idCardBack with the new value but also updates the idCardFront with the previous value saved in the previos identificationCard component enter image description here

im assuming that when i update the state, given that the onCompleted function is being called again after each upload, the map checks the current value and updates the second object, but im not sure how to get out of the function while storing each link on its corresponding key, any help will be much appreciated

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