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

138
Vistas
Asignar un valor a una lista de elementos

Estoy tratando de actualizar cada respuesta en una lista para poder pasar cada respuesta a redux y enviar todas las respuestas a una API.

He intentado pasar cada respuesta como una variable y asignarla a un estado en una matriz. Estoy realmente confundido por esto.

 const DATA = [{ id: '1', title: 'Do you feel appropriately rewarded for your work?', }, { id: '2', title: 'Are you happy with your working hours?', }, { id: '3', title: 'Do you feel recognised when you do something well?', }, { id: '4', title: 'Do you have enough information to do your job well?', }, { id: '5', title: 'Do you have the resources you need to do your job well?', }, { id: '6', title: 'Do you feel empowered to make decisions?', }, ]; const [data, setData] = useState(''); let newData = [...data]; const questionIndex = newData.findIndex((q, i) => q.id == idVariable); if (questionIndex > -1) newData[questionIndex].answer = answerVariable; const handleSubmit = () => { navigation.navigate('SplashScreen') setData(newData); console.log("hey", newData) }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

import React, { useEffect, useState } from "react"; const data = [{ id: '1', title: 'Do you feel appropriately rewarded for your work?', }, { id: '2', title: 'Are you happy with your working hours?', }, { id: '3', title: 'Do you feel recognised when you do something well?', }, { id: '4', title: 'Do you have enough information to do your job well?', }, { id: '5', title: 'Do you have the resources you need to do your job well?', }, { id: '6', title: 'Do you feel empowered to make decisions?', }, ];
about 4 years ago · Juan Pablo Isaza Denunciar

0

debería ser así, pelease intente, ya que setState udate de esa manera no obtendrá resultados inmediatamente

 const [questions, setQuestions] = useState(DATA) const handleSubmit = () => { setQuestions((prevState) => { const questionIndex = prevState.findIndex((question) => question.id === idVariable) if (questionIndex > -1) { questions[questionIndex].answer = answerVariable; } return questions; }); navigation.navigate('SplashScreen') console.log("hey", newData) }
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