default select on react-select code example
Example 1: react select with custom option
import React from "react";
import ReactDOM from "react-dom";
import Select from "react-select";
const options = [
{ value: "Abe", label: "Abe", customAbbreviation: "A" },
{ value: "John", label: "John", customAbbreviation: "J" },
{ value: "Dustin", label: "Dustin", customAbbreviation: "D" }
];
const formatOptionLabel = ({ value, label, customAbbreviation }) => (
<div style={{ display: "flex" }}>
<div>{label}</div>
<div style={{ marginLeft: "10px", color: "#ccc" }}>
{customAbbreviation}
</div>
</div>
);
const CustomControl = () => (
<Select
defaultValue={options[0]}
formatOptionLabel={formatOptionLabel}
options={options}
/>
);
ReactDOM.render(<CustomControl />, document.getElementById("root"));
Example 2: react-select
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} />
)