Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
formatCreateLabel does not display "Create new label..." for some cases react-slect/creatable

I am using react-select/creatable library to display dropdowns with options. I wanted to make use of the formatCreateLabel prop which displays a label. This label is based on the topmost option in the dropdown, so essentially in the formatCreateLabel function, I am sorting my list which is dynamic, and based on the topmost option I am showing the create option. Few things to note here - the create option is dependent on the topmost option in the dropdown list. I also wanted to show the create option even if there is an exact match.

Snippet of the format function -

const formatCreateLabel = (input) => {
        
        const options = getSortedList(input, list); // using sort-matcher library for sorting
    
        const firstItem = _.first(options);
        const label = _.get(firstItem, 'label');

        if (!_.isNil(firstItem))
            return `Create wildcard "${label}"`;
    };

/** My list option looks something like this (eg.)
    const listOptions = [
         { label: 'alpha', key: 'a', value: 'a' },
         { label: 'alpea', key: 'ae', value: 'ae' },
         { label: 'beta', key: 'b', value: 'b' },
         { label: 'user.name', key: 'user.name', value: 'user.name' },
         { label: 'name', key: 'name', value: 'name' },
    ];
**/


   <CreatableSelect
      key={key}
      options={list}
      value={value}
      onChange={onChange}
      placeholder="Select..."
      formatCreateLabel={formatCreateLabel}
      {...props}
  />

The issue is the label is sometimes shown sometimes it is not although I can see that a valid value is being returned from the formatCreateLabel function. What could be the issue here? Also is there a way to continue showing the create new option even if there is an exact match?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!