Created
March 14, 2023 08:42
-
-
Save hujuu/40e2ea7d7d153504a57d1b3cadaf3363 to your computer and use it in GitHub Desktop.
react-selectのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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