react-select-country-list icon indicating copy to clipboard operation
react-select-country-list copied to clipboard

Duplicate label when using setEmpty()

Open mcelearr opened this issue 3 years ago • 0 comments

When I set an initial empty value like so:

  const countries = useMemo(() => {
    return countryList().setEmpty("Select a Country").getData();
  }, []);

I end up with a duplicate empty value Screenshot 2022-01-12 at 17 39 41

Am I using the .setEmpty() method wrong?

I messed around with the setEmpty() method and saw that changing to a .concat method instead of .unshift fixed the problem for me. Not sure why. Want me to open a PR or can you think of a cleaner way to do it?

  setEmpty(label) {
    this.data = [{
      value: '',
      label: label,
    }].concat(this.data)
    this.valueMap[''] = label
    this.labelMap[label] = ''

    return this
  }

mcelearr avatar Jan 12 '22 18:01 mcelearr