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

94
Vistas
select one of arr index in REACT

I have an arr.map rendered in html, how can I do it to select one of them

my arr is like [{progress: "A" , _id: "123456"}, {progress: "A" , _id: "222363"} , ....... ]

Example: Press the first btn to select arr[0]. Press the third btn to select arr[2].

Below is the html document

arr.map((arr) => (
    <div className={arr._id} id="bookingdata" >
       <div className="booking-detail">
          <p className="booking-id" id="booking-id">
            {arr._id}
          </p>
          <p className="booking-progress">
            {arr.progress}
          </p>
          <button onClick={handledetail} className="btn">
             btn
           </button>
        </div>
      </div>));

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

0

In your array of objects add one more field as isSelected and mark it as false intially 
const [data,setData]=useState(arr)

data.map((arr) => (
    <div className={arr._id} id="bookingdata" >
       <div className="booking-detail">
          <p className="booking-id" id="booking-id">
            {arr._id}
          </p>
          <p className="booking-progress">
            {arr.progress}
          </p>
          <button onClick={()=>{arr.isSelected=true}} class="btn">
             btn
           </button>
        </div>
      </div>));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Many ways to do it.

If u will have a lot of items, and u want to solve it with a single handler, u can do something like this:

(in your css u will need a "selected" class)

const [selectedId, setSelectedId] = useState();

function handledetail(e) {
    setSelectedId(e.currentTarget.dataset.id); // if "_id" is number Number(e.currentTarget.dataset.id)
    ...
}

data.map((item) => (
    <div className={`${item._id} ${selectedId === item._id ? "selected" : ""}`} id="bookingdata" >
        <div className="booking-detail">
            ...
            <button onClick={handledetail} data-id={item._id} className="btn">
                btn
            </button>
        </div>
    </div>
));
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