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.

I cannot for the life of me figure out how to make newOptionCreator work.

This is what I have so far:

const ContactSelect = React.createClass({
  handleChange(input) {
    this.props.onContactChange(input.value);
  },
  onNewOption(newOption) {
    return { value: newOption.label, label: newOption.label };
  },
  render() {
    return (
      <Creatable
        name="contact-select"
        value={this.props.contact}
        resetValue={{ value: '' }}
        placeholder="Choose a contact (optional)..."
        options={this.props.contactOptions}
        onChange={this.handleChange}
        newOptionCreator={this.onNewOption}
      />
    );
  },
});

The new option does not get shown or selected. What am I missing here?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
andremecommented, Oct 18, 2016

This is how it looks in the source, you might be missing the class?

https://github.com/JedWatson/react-select/blob/master/src/Creatable.js#L234

0reactions
tim-phillipscommented, Aug 23, 2017

@Geczy I’m so very sorry for the delay in getting back to you.

onContactChange() sets state in the parent component:

onContactChange(contact) {
  this.setState({ contact })
}

this.state.contact is then passed down to ContactSelect in the contact prop, which is why it is seen in my original post as this.props.contact.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using newOptionCreator prop with Creatable only allows ...
I'm using the newOptionCreator prop to add a property to the newly created option before saving the data to an endpoint.
Read more >
with redux-form and react-select.creatable why does a blur ...
summary: i'm using react-select.creatable as an autocomplete component for an email dropdown. selecting an email sets the client on the invoice ...
Read more >
react-select-legacy
newOptionCreator, function, Factory to create new option. Expected signature: ({ label: string, labelKey: string, valueKey: string }): ...
Read more >
src/types/react-select/index.d.ts · 唐嘉勇/bricks
newOptionCreator ?: NewOptionCreatorHandler<TValue>;. /**. * Creates prompt/placeholder for option text. */. promptTextCreator?: PromptTextCreatorHandler;.
Read more >
api documentation for react-select (v0.9.1)
newOptionCreator (); function react-select.propTypes.noResultsText (); function react-select.propTypes.onBlur (); function react-select.propTypes.
Read more >

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