-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathResults.js
51 lines (47 loc) · 1.23 KB
/
Results.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
import React, { useRef } from 'react'
import PropTypes from 'prop-types'
import ResultsItem from './ResultsItem'
const Results = ({ items }) => {
const containerEl = useRef(null)
return (
items.length > 0 && (
<>
<section className="callout primary" ref={containerEl}>
{items.map((item) => (
<ResultsItem
key={item.id}
id={item.id}
title={item.title}
url={item.url}
rating={item.rating}
previewUrl={item.previewUrl}
/>
))}
</section>
<footer className="text-center">
<button
type="button"
className="button"
onClick={() => {
containerEl.current.scrollIntoView(true)
}}
>
To top
</button>
</footer>
</>
)
)
}
Results.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
rating: PropTypes.oneOf(['G', 'PG', 'PG-13', 'R']).isRequired,
previewUrl: PropTypes.string.isRequired,
}),
).isRequired,
}
export default Results