Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate label when using setEmpty() #10

Open
mcelearr opened this issue Jan 12, 2022 · 0 comments
Open

Duplicate label when using setEmpty() #10

mcelearr opened this issue Jan 12, 2022 · 0 comments

Comments

@mcelearr
Copy link

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
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant