Home > Software design >  passing data when click dropdown button
passing data when click dropdown button

Time:11-16

I'm using React and I'm making a lotery app and my app uses an RestAPI to load data every saturday.

I have a dropdown with differents dates and I want to pass the date when you clicked the button, but I don't know how to passed date like a parameter when you click it

Dropdown picture

<div className="btn-group">
 <div className="dropdown">
   <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" 
   data-bs-display="static" aria-expanded="false">
    Sorteos Anteriores
   </button>
    <ul className="dropdown-menu" aria-labelledby="dropdownMenuLink">
          {PrevDraws.map((index, i) => (
        <li> 
          <button obj={index} key={i} className="dropdown-item" type="button">       
            {PrevDraws[i]}
          </button>
        </li>
      ))}
    </ul>
  </div>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

you can call your function in onClick

 <button obj={index} key={i} className="dropdown-item" type="button" 
 onClick={()=>{console.log(PrevDraws[i])}} >       

 {PrevDraws[i]}

 </button>
  • Related