JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.63k stars 4.13k forks source link

let asyncOptions accept promises #491

Closed dmatteo closed 9 years ago

dmatteo commented 9 years ago

Looking at the doc here https://github.com/JedWatson/react-select#async-options and after having tried a bit, it doesn't seem that asyncOptions is able to use promises.

Being able to do something like this would be great:

  render() {

    return (
      <Select
        name={this.props.name}
        asyncOptions={this.fetchOptions.bind(this)}
        onChange={this.handleChange.bind(this)}
        valueRenderer={this.renderValue}  />
    );
  }

  fetchOptions(query) {
    return fetch(`some/uri/with/${query}`)
      .then((response) => {
        return response.json();
      })
  }

Any support or interest for a PR?

JedWatson commented 9 years ago

I'd happily merge a PR adding promise support for asyncOptions

dmatteo commented 9 years ago

Do you think it would be better to create another prop for that or just "extend" asyncOptions ?

I am worried about adding unnecessary complexity to asyncOptions here.

dmatteo commented 9 years ago

After a bit of research, I'm more convinced we should have a different prop for the promises, or break the current API with asyncOptions and always assume a promise is passed in.

Detecting promises with certainty is expensive: https://github.com/promises-aplus/promises-tests