-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchPhotos.js
44 lines (43 loc) · 1.15 KB
/
searchPhotos.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
import React, { useState } from "react";
import Unsplash,{toJson} from "unsplash-js";
const unsplash = new Unsplash({
accessKey: "Hl5oN25XcGe852HvnYf1D_MPcaytd2iVHTHCsbYQTRk",
});
export default function SearchPhotos(unsplash)
{
const [query, setQuery] = useState("");
const [pics, setPics] = useState([]);
search.photos(keyword, page, per_page, filters)
const searchPhotos = async (e) => {
e.preventDefault();
unsplash.search
.photos(query)
.then(toJson)
.then((json) => { setPics(json.results);
});
//console.log("Submitting the Form")
};
return (
<>
<form className="form"onSubmit={searchPhotos}>
<label className="label" htmlFor="query">
{" "}
📷
</label>
<input
type="text"
name="query"
className="input"
placeholder={"Search free high-resolution photos"}
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<button type="submit" className="button">
Search
</button>
</form>
<div className="card-list">
</div>
</>
);
}