noOptionsMessage with getOptionLabel in CreatableSelect #5047
-
Hello Do I really need to cast my object to {label: "", value: ""}? I'm fetching categories from an endpoint and saving it to useState<CategoryViewModel[]>([])
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @emil-malmgaard-rasmussen,
<Creatable
// Assuming accessors are written to work with shape `{ id, name }`
getNewOptionData={(inputValue, optionLabel) => ({
__isNew__: true,
id: inputValue,
name: optionLabel
})}
/> Additionally you can change the default create prompt with the help of the So no, options don't have to equal the shape |
Beta Was this translation helpful? Give feedback.
Hello @emil-malmgaard-rasmussen,
noOptionsMessage
is only used if there are no options. But the prompt to create new options is treated as its own option, with a special flag on it. This special option has to be formatted to work withgetOptionValue
andgetOptionLabel
with the help of thegetNewOptionData
prop:Additionally you can change the default create prompt with the help of the
formatCreateLabel
prop.So no, options don't have to equal the shape
{ label, value }
, but you have to d…