-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
error: (intermediate value).map is not a function
22.01.29 10:39 작성 조회수 653
0
import React, { useContext } from 'react';
import { ImageContext } from '../context/ImageContext';
const ImageList = () => {
const { images, myImages, isPublic, setIsPublic } = useContext(ImageContext);
console.log(myImages);
const imgList = (isPublic ? images : myImages).map((image) => (
<img
alt=""
key={image.key}
style={{ width: '100%' }}
src={`http://localhost:8000/uploads/${image.key}`}
/>
));
return (
<div>
<h3 style={{ display: 'inline-block', marginRight: 10 }}>
Image List({isPublic ? '공개' : '개인'} 사진)
</h3>
<button onClick={() => setIsPublic(!isPublic)}>
{(isPublic ? '개인' : '공개') + ' 사진 보기'}
</button>
{imgList}
</div>
);
};
export default ImageList;
const [myImages, setMyImages] = useState([]);
답변을 작성해보세요.
0
답변 1