When I try to .map the image i get from the parent component so as to render the images gotten from unsplash, i get a type error .map is not a function error. I have attached code for the problem. if error is solved it is meant to show the images from the search bar
import React, { useState } from 'react';
import axios from 'axios';
import SearchBar from '../SearchBar/SearchBar';
import ImageList from '../ImageList/ImageList';
const API_KEY = process.env.REACT_APP_ACCESS_KEY;
const SearchPage = () => {
const [searchText, setSearchTerm] = useState('');
const [image, setImage] = useState([]);
const onInputChange = (e) => {
setSearchTerm(e.target.value);
};
const fetchImages = () => {
axios.get('https://api.unsplash.com/search/photos', {
params: { query: searchText },
headers: {
Authorization: API_KEY,
},
})
.then((data) => {
setImage(data.data);
});
};
console.log(image);
const onSubmitHandler = (e) => {
e.preventDefault();
fetchImages();
};
return (
<div>
<SearchBar
onSubmitHandler={onSubmitHandler}
onInputChange={onInputChange}
searchText={searchText}
/>
<ImageList image={image} />
</div>
);
};
export default SearchPage;
---------------------------------------------------------------------
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable react/prop-types */
import React from 'react';
const ImageList = ({ image }) => {
const imgs = image && image.map(img => (
<img
key={img.id}
src={img.urls.regular}
/>
));
return (
<div>
{' '}
{imgs}
{' '}
</div>
);
};
export default ImageList;
When I try to .map the image i get from the parent component so as to render the images gotten from unsplash, i get a type error .map is not a function error. I have attached code for the problem. if error is solved it is meant to show the images from the search bar
console.logthe image propertyconsole.log(data.data)and add to your question what you see