As title states, setting initial value for Select.Async is possible but failed to show the label due to the empty callback options from loadOptions.
Is there any workaround ?
I tried #861 but not quite fit the scenario.
Thanks in advance.
Here is my workaround...
I marked on Select and depended on the state "isFirstTime"
constructor() {
this.state = {
isFirstTime: true,
};
this.loadAsyncOptions= this.loadAsyncOptions.bind(this);
}
loadAsyncOptions(input, callback) {
if(input) {
if (this.state.isFirstime) {
this.setState({
isFirstTime: false,
});
callback(null, options: [ { ... } ]); // your default options
return;
}
callback(null, options: [ { ... } ]); // other options...
return;
}
}
render() {
return(<div>
<Select.Async
loadOptions={this.loadAsyncOptions}
/></div>);
}
Thanks for the reply.
I actually have this problem fixed with my workaround and send a PR.
So far, it works just fine.
For your reference, https://github.com/JedWatson/react-select/pull/1180
I actually created another PR that will fix this issue as well: The ability to pass an options array to Select.Async.
FYI I am working on a refactor for Async that should address this issue. (See PR #1226)
Resolved via PR #1226.
Look for an RC2 to come out (hopefully) sometime today with this change.
How does the initial value work? Is there an example for that? I tried defaultOptions, defaultValues but none of them work.
I see why it doesn't work for me. The defaultValues in my component is also an async request. How can I make it work with async data?
I see why it doesn't work for me. The
defaultValuesin my component is also an async request. How can I make it work with async data?
As 2020, is there any solution?
Most helpful comment
Here is my workaround...
I marked on Select and depended on the state "isFirstTime"