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 working- Newly created value not getting set

See original GitHub issue

Hi @bvaughn ,

I’m using the AsyncCreatable component and facing an issue where the newly created value is not getting applied. Here’s the code:

import React, { Component } from "react";
import { autobind } from "core-decorators";
import axios from "axios";
import { AsyncCreatable } from "react-select";


@autobind
class SampleComponent extends Component {
       constructor(){
           super();
           this.state={ usaStates: {} }
       }
	onChange(itemId, selectedItem) {
		this.setState({
			[itemId]: selectedItem || {}
		});
	}
	loadStateData(input, callback) {
		axios("/data/states.json").then((response) => {
			callback(null, { options: response.data, complete: true });
		});

	}
	render() {
		return <AsyncCreatable id="usaStates" value={this.state["usaStates"].value} loadOptions={this.loadStateData} onChange={this.onChange.bind(this, "usaStates")}></AsyncCreatable>;
	}
}

export default SampleComponent;

Is there a fix/workaround for this? Any input appreciated. Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:9

github_iconTop GitHub Comments

1reaction
desigenscommented, Jan 24, 2018

Here is an example of the issue: https://codesandbox.io/s/43ym8zxzk7

You can download code to local disk.

0reactions
ebonowcommented, Dec 19, 2020

As @elie222 stated, the onCreateOption does not call onChange as per the documentation.

I will be closing this issue now, but if there are any other questions or concerns, feel free to create a new ticket or discussion to address these.

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 >
react-select-old - npm
Start using react-select-old in your project by running `npm i ... Select ) to allow new options to be created if they do...
Read more >
Advanced - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
How to use the react-select.Async function in react-select | Snyk
To help you get started, we've selected a few react-select. ... Use Snyk Code to scan source code in minutes - no build...
Read more >
React-Select Makes Creating Selectable Menus Easy
Line 20: Shows the loading animation with isLoading being set. Line 22: Shows the preselected value, “Apple” . Since isClearable is set, it...
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