Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

select html react

import React, { useState } from 'react'


const ANIMALS = ['Dog', 'Cat', 'Lion', 'Elephant'];

export const Example = ()=>{
const [animal, setAnimal] = useState("");


return (
<div>
  <form>
    <label htmlFor="animal">
    Animal: 
      <select
          id="animal"
          value={animal}
          onChange={(e)=>{setAnimal(e.target.value)}}
        >
        <option>Select Option ... </option>
        
      	{ANIMALS.map((animal)=>(
        <option key={animal}>{animal}</option>
        ))
        }
      </select>
    </label>
  </form>
</div>
)
}
 
PREVIOUS NEXT
Tagged: #select #html #react
ADD COMMENT
Topic
Name
6+2 =