How to change mapping option label/value to id/name #100
-
Thank you for your nice contribution. Default option type is {
value: "coffee",
label: "Coffee",
} But I want to use like this {
id: "coffee",
name: "Coffee",
} How can I do that? |
Beta Was this translation helpful? Give feedback.
Answered by
joao-salomao
Feb 9, 2022
Replies: 2 comments
-
@abinhho you can use the props |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
csandman
-
@joao-salomao Thanks for helping out here, and you're spot on. Here's a full example using import { Select } from "chakra-react-select";
const options = [
{ id: "vanilla", name: "Vanilla" },
{ id: "chocolate", name: "Chocolate" },
{ id: "strawberry", name: "Strawberry" },
{ id: "salted-caramel", name: "Salted Caramel" }
];
const Example = () => (
<Select
isMulti
name="flavors"
options={options}
placeholder="Select some flavors..."
getOptionLabel={({ name }) => name}
getOptionValue={({ id }) => id}
/>
);
export default Example; CodeSandbox Link: https://codesandbox.io/s/chakra-react-select-custom-label-and-value-qn8je?file=/example.js |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@abinhho you can use the props
getOptionLabel
andgetOptionValue
from react select