question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onCreateOption is not called, fails at `valueArray[valueArray.length - 1] === newOption`

See original GitHub issue

Getting a weird bug at this line.

https://github.com/JedWatson/react-select/blob/c8d74bd5710b1db6736837fb4334a59e46614a27/packages/react-select/src/Creatable.js#L148

It seems that the === comparison fails on this line.

valueArray[valueArray.length - 1] === newOption

I put debugger breakpoint and inspected the values. Please see the console output.

> valueArray[valueArray.length - 1] === newOption
false
> newOption === newValue 
false
> newOption
{label: "Create "sd"", value: "sd", __isNew__: true}
> newValue
{label: "Create "sd"", value: "sd", __isNew__: true}
> valueArray
[{…}]0: {label: "Create "sd"", value: "sd", __isNew__: true}length: 1__proto__: Array(0)
> valueArray.length
1

It looks like the newOption and newValue have the same content by they fail when compared using === operator. As the result the onCreateOption is not called.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
hamfzcommented, Aug 8, 2020

For anyone struggling with this in the interim, you can use the getNewOptionData prop to bust the equality check and properly pass through to onCreateOption.

Ex:

getNewOptionData={(inputValue, optionLabel) => ({
     value: inputValue,
     label: optionLabel,
     __isNew__: true,
     isEqual: () => false
  })
}

2reactions
nikitaindikcommented, Mar 28, 2020

@gwyneplaine Please check out the fix and tell me what you think. I’ve ran the tests and did some manual testing on the docs page - everything seems to be fine. I’d be happy to add a test, but I’ll need a little guidance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found