Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Quiero mostrar botones de funcionamiento dinámico, basados en la lista de preguntas. Cualquier sugerencia sería buena
export const QuizData = [ { id: 0, question: `What is the Capital of India?`, options: [`New Delhi`, `Mumbai`, `Pune`, `Hyderabad`], answer: `New Delhi` }, { id: 1, question: `Any question here`, options: [`any`, `options`, `here`, ` `], answer: `ans` }, { id: 2, question: `Any question here`, options: [`any`, `options`, `here`, ` `], answer: `ans` }, ] //buttons <button className="btn btn-primary" onClick={() => this.indexHandler(0)} > 1 </button> <br /> <button className="btn btn-primary" onClick={() => this.indexHandler(1)} > 2 </button> <br /> <button className="btn btn-primary" onClick={() => this.indexHandler(2)} > 3 </button>

Más arriba se menciona la lista de preguntas de referencia. Entonces, por ahora estoy usando botones estáticos (por ejemplo, en //Botones) y lo que quiero es, dependiendo de la cantidad de preguntas de los datos, se debe crear la misma cantidad de botones.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Un buen enfoque sería mantener dos componentes separados:

  1. Componente que enumerará las preguntas (por ejemplo, QuestionList.js )
  2. Componente específico de pregunta para manejar las acciones realizadas en esa pregunta en particular. (decir Question.js )

QuestionList.js

 const QuestionList = () => { const QuizData = [...] const indexHandler = (id) => {...} return( <> {QuizData.map(question => ( <Question key={question.id} id={question.id} indexHandlerCallback={indexHandler} /> ))} </>) }

Pregunta.js

 const Question = ({ id, indexHandlerCallback }) => { const hanldeClick = () => { // dispatch callback or any other actions } return ( <button className="btn btn-primary" onClick={hanldeClick}> {id+1} </button> ) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!