-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
73 lines (64 loc) · 1.79 KB
/
App.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, { useState } from 'react'
const Result = ({ title, url, previewUrl, rating }) => {
return (
<div
className="card"
style={{
width: '300px',
display: 'inline-block',
marginRight: '16px',
}}
>
<video src={previewUrl} alt={title} loop autoPlay />
<section className="card-section">
<h5>
<a href={url} target="_blank" rel="noopener noreferrer">
{title}
</a>{' '}
({rating})
</h5>
</section>
</div>
)
}
const SearchForm = ({ query, onQueryChange }) => {
return (
<div style={{ maxWidth: 400, margin: '20px auto' }}>
<input
type="search"
placeholder="Search Giphy"
value={query}
// Call `onQueryChange` prop from the
// `onChange` prop of the input
onChange={(e) => onQueryChange(e.target.value)}
/>
</div>
)
}
const GiphySearch = ({ initialQuery }) => {
// Define the query state
const [query, setQuery] = useState(initialQuery)
const title = "I'm Ready Lets Go GIF by Leroy Patterson"
const url =
'https://giphy.com/gifs/leroypatterson-cat-glasses-CjmvTCZf2U3p09Cn0h'
const previewUrl =
'https://media2.giphy.com/media/CjmvTCZf2U3p09Cn0h/giphy-preview.mp4?cid=376dcdd944vhe2rsqwiiqnrfkuh6v7qw9cuermk7bsxburuv&rid=giphy-preview.mp4'
const rating = 'G'
return (
<main>
<h1>Giphy Search!</h1>
{/* pass `setQuery as `onQueryChange` prop */}
<SearchForm query={query} onQueryChange={setQuery} />
<div className="callout primary">
<Result
title={title}
url={url}
previewUrl={previewUrl}
rating={rating}
/>
</div>
</main>
)
}
const App = () => <GiphySearch initialQuery="cats" />
export default App