Home > Mobile >  How to get id instead of name with react
How to get id instead of name with react

Time:01-30

I need the name of the states to be displayed in the options, but I need to get the id instead of the name

code image

The e.target.value only takes the name (a string), I need to get the id of the selected object or the entire object so that I can extract the id.

The id is needed to be able to send the object to the backend.

I already tried to use several methods of e.target, but I didn't get any result

CodePudding user response:

<option value={states.id} value={states.id}>Volvo</option>

add value to options

  • Related