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

190
Views
¿Cómo puede ser verdadera una propiedad de un objeto de una matriz si esa propiedad de otros objetos es falsa?

Tengo un estado de matriz:

 const [photos, setPhotos] = useState( [ { id:1, name:'Jack Stipen', isActive:true }, { id:2, name:'Reshma Karim', isActive:false }, { id:3, name:'Jahid Jader', isActive:false }, { id:3, name:'Bindu Jemaiya', isActive:false }, ] );

Solo quiero que la propiedad de un objeto sea verdadera y el resto sea falsa .

Tengo una función para seleccionar una propiedad de objeto para que sea verdadera. ¡Pero deshecho!

 const handleDefaultPhotoOnTable = ( id, e ) => { const exitPhotos = [...photos]; const selectTablePhotoIndex = exitPhotos.findIndex( photo => photo.id === photoId ); exitPhotos[selectTablePhotoIndex].isActive= e.target.checked; setPhotos( exitPhotos ); ........ };

Aquí encuentras mi código HTML:

 <tbody> { photos.map( ( photo ) => ( <tr key={photo.id}> <td>{photo.name}</td> <td className="text-center"> <input onChange={( e ) => { handleDefaultPhotoOnTable( photo.id, e ); }} name='isActive' checked={photo.isActive} type='checkbox' id='defaultId' /> </td> </tr> ) ) } </tbody>

Por favor, ayúdame.

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

0

Puede usar un bucle de mapa para este caso como este:

 setPhotos( photos.map((photo) => photo.id === photoId ? { ...item, isActive: true } : { ...item, isActive: false } ) );
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!