-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
4-Async.stories.js
59 lines (56 loc) · 1.73 KB
/
4-Async.stories.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import SelectSearch from '../src';
import '../style.css';
export default {
title: 'Async',
};
export const Fetch = () => (
<SelectSearch
options={[]}
defaultValue="15997"
getOptions={(query) => {
return new Promise((resolve, reject) => {
fetch(
`https://www.thecocktaildb.com/api/json/v1/1/search.php?s=${query}`,
)
.then((response) => response.json())
.then(({ drinks }) => {
resolve(
drinks.map(({ idDrink, strDrink }) => ({
value: idDrink,
name: strDrink,
})),
);
})
.catch(reject);
});
}}
search
placeholder="Your favorite drink"
/>
);
export const FetchMultiple = () => (
<SelectSearch
options={[]}
multiple
getOptions={(query) => {
return new Promise((resolve, reject) => {
fetch(
`https://www.thecocktaildb.com/api/json/v1/1/search.php?s=${query}`,
)
.then((response) => response.json())
.then(({ drinks }) => {
resolve(
drinks.map(({ idDrink, strDrink }) => ({
value: idDrink,
name: strDrink,
})),
);
})
.catch(reject);
});
}}
search
placeholder="Your favorite drink"
/>
);