Skip to content

Instantly share code, notes, and snippets.

@hujuu
Created March 14, 2023 08:42
Show Gist options
  • Save hujuu/40e2ea7d7d153504a57d1b3cadaf3363 to your computer and use it in GitHub Desktop.
Save hujuu/40e2ea7d7d153504a57d1b3cadaf3363 to your computer and use it in GitHub Desktop.
react-selectのサンプル
'use client';
import {useState} from "react";
import Select from "react-select";
const options = [
{value: "line", label: "折れ線グラフ"},
{value: "bar", label: "棒グラフ"},
{value: "pie", label: "円グラフ"},
];
export default function Demo() {
const [selectedValue, setSelectedValue] = useState(options[0]);
return (
<div>
<div style={{width: "600px", margin: "50px"}}>
<Select
options={options}
defaultValue={selectedValue}
onChange={(value:any) => {
value ? setSelectedValue(value) : null;
}}
/>
</div>
<div>{selectedValue.value}</div>
<div>{selectedValue.label}</div>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment