Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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>
)
}
Comment

select in react js

import React, { useState } from 'react'

export const FruitSelectDropdown = () => {
  const [currentFruit, setCurrentFruit] = useState('oranges')
  
  const changeFruit = (newFruit) => {
    setCurrentFruit(newFruit)
  }
  
  return (
    <form>
      <select 
        onChange={(event) => changeFruit(event.target.value)}
        value={currentFruit}
      >
        <option value="apples">Red Apples</option>
        <option value="oranges">Outrageous Oranges</option>
        <option value="tomatoes">Technically a Fruit Tomatoes</option>
        <option value="bananas">Bodacious Bananas</option>
      </select>
    </form>
  )
}
Comment

react select options

import React, { Component } from 'react'
import Select from 'react-select'

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

const MyComponent = () => (
  <Select options={options} />
)
Comment

react select

import React from 'react'
import Select from 'react-select'

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

const MyComponent = () => (
  <Select options={options} />
)
Comment

html select react

class FlavorForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: 'coconut'};
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {    this.setState({value: event.target.value});  }
  handleSubmit(event) {
    alert('Your favorite flavor is: ' + this.state.value);
    event.preventDefault();
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          Pick your favorite flavor:
          <select value={this.state.value} onChange={this.handleChange}>            <option value="grapefruit">Grapefruit</option>
            <option value="lime">Lime</option>
            <option value="coconut">Coconut</option>
            <option value="mango">Mango</option>
          </select>
        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}
Comment

react select

import React, { Component } from 'react'
import Select from 'react-select'

const options = [
  { value: 'vanilla', label: 'Chocolate' },
  { value: 'vanilla', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

const MyComponent = () => (
  <Select options={options} />
)
Comment

REACT SELECT DROPDOWN

const [tags, setTags] = useState([])
const [tagsData, setTagsData] = useState([]);

useEffect(() => {
        (async () => {
            const { data } = await axios(`${process.env.REACT_APP_API_URL}/tag`);
            setTagsData(data);
            setTags([data[0]]);
        })();
    }, []);

<Select
    id="react-select-tag"
    isMulti
    options={tagsData}
    hideSelectedOptions={false}
    getOptionLabel={(option) => option.content_tag}
    getOptionValue={(option) => option.id} // using id as it is unique
    value={tags}
    onChange={(selected) => setTags(selected)}
/>
Comment

react select options

yarn add react-select
Comment

react select

npm i --save react-select // with npm
Comment

react-select

yarn add react-select
or 
npm i react-select
Comment

react select

inputValue: "uuuuu"
Comment

PREVIOUS NEXT
Code Example
Javascript :: validation select option jquery 
Javascript :: javascript get specific timezone 
Javascript :: define an unsigned long int js 
Javascript :: vuejs cant add script in template 
Javascript :: email regular expression javascript 
Javascript :: javascript button onclick reload page 
Javascript :: laravel http send data json raw 
Javascript :: javascript extract date from string 
Javascript :: javascript Swapping Variables 
Javascript :: Find the maximum number in a jagged array of numbers 
Javascript :: jquery change select value 
Javascript :: nuxt query params 
Javascript :: angular is not defined In AngularJS 
Javascript :: run onclick function once 
Javascript :: selector id jquery but is variable 
Javascript :: javascript check for null variables 
Javascript :: node.js child processes 
Javascript :: sequelize change column 
Javascript :: Summernote keyup event jquery 
Javascript :: javascript execute powershell script 
Javascript :: convert string uppercase javascript 
Javascript :: focus element javascript 
Javascript :: regex js pattern tags 
Javascript :: javascript sum table row values 
Javascript :: react usereducer 
Javascript :: react native red triangle up 
Javascript :: json stringify double quotes 
Javascript :: count javascript 
Javascript :: how to create package.json file in vs code 
Javascript :: webpack-bundle-analyzer react 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =