From c722bd9431addca14ccb457bc8f6a2ce4a4547a0 Mon Sep 17 00:00:00 2001 From: Domenico Matteo Date: Thu, 22 Oct 2015 19:48:24 +0200 Subject: [PATCH 1/2] docs(asyncOptions): now accepting Promises --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 0a51df9b91..a39a556fa0 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,41 @@ var getOptions = function(input, callback) { /> ``` +### Async options with Promises + +`asyncOptions` now supports Promises, which can be used in very much the same way as callbacks. + +Everything that applies to `asyncOptions` with callbacks still applies to the Promises approach (e.g. caching, autoload, ...) + +An example using the `fetch` API and ES6 syntax, with an API that returns an object like: + +```javascript +import Select from 'react-select'; + +/* + * assuming the API returns something like this: + * const json = [ + * { value: 'one', label: 'One' }, + * { value: 'two', label: 'Two' } + * ] + */ + +const getOptions = (input) => { + return fetch(`/users/${input}.json`) + .then((response) => { + return response.json(); + }).then((json) => { + return { options: json }; + }); +} + +` elements should be considered private and prone to change. -```js +```javascript // focuses the input element .focus(); ```