The form only makes the api call (submits the form) on the 2nd click. Is it the way Im using async for the arguments? Is there something wrong with my function?
Handler Function:
const handleSubmit = async e => {
e.preventDefault();
searchAllImages(keyword);
};
const searchAllImages = async (keyword) => {
const response = await searchImages(keyword);
setImagelinks(response.data.message);
const imageObjects = imagelinks.map((link, index) => {
let newImage = {
url: link,
id: index,
fav: false
};
return newImage;
});
setImages(imageObjects);
};
Form:
<Form inline onSubmit={handleSubmit} className="form">
<Form.Row>
<Form.Group as={Col} md="12" controlId="keyword">
<Form.Control
type="text"
name="keyword"
value={keyword}
onChange={e => setKeyword(e.target.value)}
placeholder="Search a Dog"
/>
</Form.Group>
</Form.Row>
<Button type="submit" className="button">
Search
</Button>
</Form>