Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

use onchange with react select

const [valueState,setValueState] = useState("")
// create a function that handle the React-select event and
// save the value of that event on an state every time the component change
    const handler = (event) => {
        const value = event.value
        setValueState(value)
    }
<Select options={"your options"} onChange={handler}/>
Comment

select in react with nchange

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

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

class App extends React.Component {
  state = {
    selectedOption: null,
  };
  handleChange = selectedOption => {
    this.setState({ selectedOption });
    console.log(`Option selected:`, selectedOption);
  };
  render() {
    const { selectedOption } = this.state;

    return (
      <Select
        value={selectedOption}
        onChange={this.handleChange}
        options={options}
      />
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: canactivate angular 
Javascript :: javascript competitive programming 
Javascript :: how to get file type in javascript 
Javascript :: regex remove duplicates 
Javascript :: require a json as a string 
Javascript :: how to convert a queryset into json string 
Javascript :: how to send a request to a web server javascript 
Javascript :: fuse.js npm 
Javascript :: how to create a folder using fs in node js 
Javascript :: save image jpg javascript 
Javascript :: run onclick function once js 
Javascript :: how to find all elements starting with class jquery 
Javascript :: js array last element get 
Javascript :: replace object in array with another array with same id javascript 
Javascript :: Lazy Loading Routes vue 
Javascript :: regex find first instace 
Javascript :: delete all objects in array of objects with specific attribute 
Javascript :: tailwind content for nextjs 
Javascript :: uppercase in javascript 
Javascript :: react port 
Javascript :: javascript date object format yyyy mm dd 
Javascript :: javascript loop x times 
Javascript :: sequelize migration add column 
Javascript :: inline styling in react 
Javascript :: cart page route in shopify 
Javascript :: Return the average of the given array rounded down to its nearest integer. 
Javascript :: node js currency format 
Javascript :: how to design an api node js 
Javascript :: js fetch api 
Javascript :: js split string every n characters 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =