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

207
Vistas
Create a list from an array react.js as a FAQ

I'm trying to create a FAQ, I have the data coming from an API but I'm having problems on how to show it on screen, here is my data

0:
answer: "The wellbeing score is Empatho's way of showing an end-user what their current state of wellbeing is. "
application: "Admin Portal"
question: "What is the wellbeing score?"
section: "Wellbeing Dashboard"
[[Prototype]]: Object
1:
answer: "The wellbeing score is calculated using an individuals Heart Rate Variability (HRV), their passive data, as well as some survey questions that help Empatho get to know a person better. "
application: "Admin Portal"
question: "How is the wellbeing score calculated?"
section: "Wellbeing Dashboard"
[[Prototype]]: Object

the React.js code I want to insert the data is:

<Accordion expanded={expanded === 'panel1'}
           onChange={handleChange('panel1')}
           sx={{ width: '100%', padding: '30px' }}
           style={{ borderRadius: 20, margin:'10px 0px' }} >

  <AccordionSummary expandIcon={<ExpandMoreIcon />}
                    aria-controls="panel1bh-content"
                    id="panel1bh-header"
                    sx={{ borderRadius:10 }} >
    
    <div style={{ display:'flex', flexDirection:'row', alignItems:'center' }}>
      <div>
        <img src={wellbeingfaq} style={{ width:'auto', height:20, marginRight:25 }}/>
      </div>
      <div style={{ fontSize:'1.5em', fontWeight:'bold' }}>Wellbeing Dashboard</div>
    </div>

  </AccordionSummary>

  <AccordionDetails sx={{ padding: '20px' }}> 

    <div style={{ fontSize:'1.3em', fontWeight:'bold' }}>
      <div>Question</div>
    </div>
    <div style={{ fontSize:'1.0em'}}>
      <div>Answer</div>
    </div>                 
      
  </AccordionDetails>     
           
</Accordion>

I want to substitute the "Question" and "Answer"

how do I do that? I'm totally lost.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to run over every item and return the JSX code that you need. This can be done with the .map function like this:

<AccordionDetails> 
{ this.state.listFromApi.map((item,index) => (
 <div key={index}>
  <div>
   <div>Question</div>
   <div>{item.question}</div>
  </div

  <div style={{ fontSize:'1.0em'}}>
   <div>Answer</div>
   <div>{item.answer}</div>
  </div>
 </div>
))}
</AccordionDetails> 

To avoid getting messy code I do recommend moving it into a function instead.

<AccordionDetails> 
 {this.renderQuestions()}
<AccordionDetails> 
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