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.

AsyncCreatable not adding to options list

See original GitHub issue

Thank you for maintaining this very useful component, I have used it with great success until I have tried to implement the AsyncCreatable component. The documentation would benefit from clear code examples.

My code:

 <AsyncCreatable
       name="event-search"
       value={this.state.Event}
       loadOptions={this.handleEventSearch}
       onChange={this.handleChangeEvents}
       newOptionCreator={this.handleCreateNewEventInput} />
  • handleEventSearch is working fine, a list of events is loaded and appears in the dropdown

  • handleChangeEvents returns the following object when a new option is selected:

{value: "some event", label: "some event", className: "Select-create-option-placeholder"}

newOptionCreator returns returns the object:

{ label: option "some event", labelKey: "label", valueKey: "value" }

I have checked the options array in the Select component, no new options are added.

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
typeofgraphiccommented, Sep 26, 2017

Switched to just using Creatable, which initially produced an error relating to the mutation of the Options array issue (see #1477). The setup and pattern to get Creatable working without error is:

 <Creatable
     value={this.state.value}
     options={this.state.options} 
     onChange={this.handleChange}
     onNewOptionClick={this.handleNewOptionClick}                        
/>

onChange deals with the selection of options that already exist in the list:

Option selected (value) --> onChange prop (value) --> handlerFn (value) --> setState Input: (value)

onNewOptionClick deals with adding new options to the list:

New Input (value) --> onNewOptionClick prop (value) --> handlerFn(value) --> setstate options: [...this.state.options, value ]

Its seems now that AsyncCreatable is probably not writing new options because the loadOptions prop was talking to a local method which returns a promise, which AsyncCreatable cannot write to.

At the very least, this highlights the need to update the documentation. Perhaps this would have been more appropriate to post on SO, but that would fail to highlight what seems to be a bug (or documentation issue) around AsyncCreatable.

1reaction
bernatfortetcommented, Jan 15, 2018

@minhquankq I ended up forking the repo and fixing it on my own: https://github.com/bernatfortet/react-select You can check the commits

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why "Create" option isn't visible in AsyncCreatableSelect in ...
I found this solution: import React from "react"; import AsyncCreatableSelect from "react-select/async-creatable"; const TestComponent ...
Read more >
Creatable - React Select
This example uses the onCreateOption prop to handle new options. ... for a second before the new option is added to the list...
Read more >
react-select - npm
Flexible approach to data, with customisable functions; Extensible styling API with emotion; Component Injection API for complete control over ...
Read more >
Async Data Fetching with React-Select - OpenReplay Blog
When this is done, we can add multiple options from the list using ... when the user's entry does not match pre-existing options...
Read more >
How To Create Searchable, Async Dropdowns with React ...
In this tutorial, you will add React Select to a project. ... Users are not provided with an option to provide a label...
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