-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.jsx
58 lines (51 loc) · 1.24 KB
/
index.jsx
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import connect from './connector';
import styles from './style';
/**
* The SuggestionList component.
*/
class SuggestionList extends Component {
static propTypes = {
onClick: PropTypes.func.isRequired,
fetching: PropTypes.bool,
suggestions: PropTypes.arrayOf(PropTypes.string),
};
static defaultProps = {
fetching: false,
suggestions: [],
};
/**
* @param { Object } nextProps Next props.
* @return {boolean}
*/
shouldComponentUpdate(nextProps) {
return nextProps.fetching === false && nextProps.suggestions;
}
/**
* @return {JSX}
*/
render() {
const { onClick, suggestions } = this.props;
if (!suggestions) {
return null;
}
return (
<div className={styles.list}>
{suggestions.map(suggestion => (
<button
className={styles.item}
onClick={onClick}
key={suggestion}
value={suggestion}
data-test-id={`searchSuggestion ${suggestion}`}
>
{suggestion}
</button>
))}
</div>
);
}
}
export { SuggestionList as UnwrappedSuggestionList };
export default connect(SuggestionList);