Skip to content

noOptionsMessage with getOptionLabel in CreatableSelect #5047

Discussion options

You must be logged in to vote

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 with getOptionValue and getOptionLabel with the help of the getNewOptionData prop:

<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 formatCreateLabel prop.

So no, options don't have to equal the shape { label, value }, but you have to d…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@emil-malmgaard-rasmussen
Comment options

Answer selected by emil-malmgaard-rasmussen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants