AsyncCreatable not adding to options list
See original GitHub issueThank 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:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
onChange deals with the selection of options that already exist in the list:
onNewOptionClick deals with adding new options to the list:
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.
@minhquankq I ended up forking the repo and fixing it on my own: https://github.com/bernatfortet/react-select You can check the commits