강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

thai pat님의 프로필 이미지
thai pat

작성한 질문수

이미지 관리 풀스택(feat. Node.js, React, MongoDB, AWS)

공개/비공개 구분해서 이미지 불러오기

error: (intermediate value).map is not a function

작성

·

902

0

ImageList.js

 

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;

 

error: (intermediate value).map is not a function

 

ImageContext.js >

const [myImages, setMyImages] = useState([]);

myImages 가 문제인거 같은데..함수가 아니라니..원인을 알 수가 없네요 ~ㅠㅠ

답변 1

0

images, myImages중에 배열이 아닌게 있어서 발생하는 오류입니다. 아마 이어지는 강의에서 디버깅을 할겁니다. 

thai pat님의 프로필 이미지
thai pat

작성한 질문수

질문하기