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

173
Vistas
How do I set state independently in a list of map components in React/React Native

I am rendering a list of elements from a json file i want to be able to let each component in the list have its own state. And be independent of the other elements in the list. I want to have only one element to be able to be clickable and not any of the others, not like what is shown currently in the picture below. [1]: https://i.stack.imgur.com/vdCnR.png

Here is the code i am currently using.

{questions
        .filter((question) => question.id === currentId)
        .map((question, index) => {
          return (
            <>
              <View key={index}>
                {question.title.hasOwnProperty("main") ? (
                  <>
                    <Text style={styles.title}>{question.title.main}</Text>
                    <Text style={styles.subtext}>{question.title.sub}</Text>
                  </>
                ) : (
                  <Text style={styles.title}>{question.title}</Text>
                )}
              </View>
              <View>
                {question.answers.map((ans, i) => (
                  <Answer id={ans.id} key={ans.id} ans={ans} />
                ))}
              </View>
            </>
          );
        })}

 const Answer = ({ ans, id }) => {
const [clkStatus, setClkStatus] = useState(false);
const [ansId, setAnsId] = useState(id);
return (
  <Card
    onPress={() => {
      if (ansId === id) {
        setClkStatus(true);
      }
    }}
    status={clkStatus && "danger"}
    style={{ marginBottom: 6, width: "100%" }}
  >
    <Text
      style={{
        textTransform: "uppercase",
        textAlign: "center",
      }}
    >
      {ans.value}
    </Text>
  </Card>
);

};

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