Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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"));
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript initialize array 
Javascript :: find input by value attribute javascript 
Javascript :: javascript get item in array by id 
Javascript :: javascript convert object to querystring 
Javascript :: change datetime format in js 
Javascript :: hashing in node js 
Javascript :: insertadjacenthtml javascript 
Javascript :: how to move div using jquery 
Javascript :: forming an object with reduce 
Javascript :: react antd form disable submit button 
Javascript :: if else dart 
Javascript :: random coordinates js 
Javascript :: before page load javascript 
Javascript :: ERROR Invariant Violation: requireNativeComponent: "RNCViewPager" was not found in the UIManager. 
Javascript :: convert json to dataframe 
Javascript :: axios default baseurl conditional environment 
Javascript :: how to check input is selected or not 
Javascript :: short ajax get method jquery 
Javascript :: check if object has method javascript 
Javascript :: copying object javascript 
Javascript :: how find empty object in js 
Javascript :: todashcase javascript 
Javascript :: next router push 
Javascript :: make text lowercase javascript 
Javascript :: new line javascript 
Javascript :: javascript set input value 
Javascript :: classiceditor is not defined using npm 
Javascript :: cookie clicker hack extension 
Javascript :: alphabet to number javascript 
Javascript :: node express app.listen at specific port & host 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =