main/index.js과 product/index.js에서 setProduct 관련 문의드립니다.
213
작성한 질문수 10
main/index.js 에서는
setProducts(result.data.products); 로 써야하고
product/index.js 에서는
setProducts(result.data); 로 써야하는데
두 파일에서 return문에서는 동등하게 {product.name} , {product.price} 등으로 사용됩니다. 둘의 차이를 알려주시면 감사하겠습니다.
답변 2
0
이는 결과적으로 서버에서 응답을 줄 때 {products: [...]}형태로 products를 key로 주었는가, 아니면 [...]으로 바로 주냐의 차이로 보시면 됩니다!
0
안녕하세요, 인프런 AI 인턴이에요.
main/index.js와 product/index.js에서 setProduct 관련 문의하신 내용에 대해 답변드리겠습니다.
먼저 main/index.js에서 setProducts(result.data.products);를 사용하고 product/index.js에서 setProducts(result.data);를 사용하고 있으신데, 두 파일에서 return문에서는 {product.name}, {product.price} 등으로 동일하게 사용되는 것이 맞나요?
setProducts는 useState 훅을 사용해 상태(state)를 업데이트하는 함수입니다. main/index.js에서 setProducts(result.data.products)을 호출하면, result.data.products의 값을 상태로 설정합니다. 반면, product/index.js에서 setProducts(result.data)를 호출하면, result.data의 값을 상태로 설정합니다.
즉, main/index.js에서는 result.data.products라는 속성에 상품 데이터가 들어있는 것으로 보이고, product/index.js에서는 result.data에 상품 데이터가 들어있는 것 같습니다.
따라서, main/index.js의 setProducts와 product/index.js의 setProducts에는 데이터 형태의 차이가 있을 수 있습니다. 두 파일에서 사용되는 {product.name}, {product.price} 등은 어떤 형태로 이루어져 있는지 확인해야 정확한 차이를 알 수 있을 것 같습니다.
더 자세한 정보를 보시기 위해서는 해당 파일의 코드를 더 자세히 살펴보셔야 할 것 같습니다.
그 외에 궁금한 점이 있으시면 언제든지 물어보세요. 도움이 될 수 있도록 최대한 도와드리겠습니다.
[해결]그랩님 답변 주세요.
0
164
2
그랩님의 답변을 기다립니다/102강 전반적인 에러
0
143
2
[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.
0
126
2
[재질문][그랩님 답변 부탁드립니다]101강
0
143
2
[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문
0
98
2
Ngrok 설치 후 forwarding Url 에러
0
133
2
[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.
0
220
2
Ngrok 설치 후 forwarding Url로 연결 불가
0
137
1
그랩님,[꼭] 답변 부탁드립니다.
0
68
1
[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.
0
153
1
6강/7강 수업
0
52
1
그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.
0
99
2
그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.
0
136
2
[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?
0
89
1
Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?
0
130
2
일반적인 css 꾸미기에서 width와 height의 값?
0
93
2
Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법
0
196
1
그랩마켓 웹화면 구현하기 -2 질문입니다.
0
121
1
react에 반영이 되지 않습니다.
0
241
1
터미널 npm install -g create-react-app 작성 후 오류
0
421
1
create-react-app my app 실행 시 에러
0
356
2
포스트맨 질문
0
100
1
<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.
0
261
2
그랩선생님, 질문 답변 부탁 드립니다.vscode에서 npm install -g create-react-app 입력 후 에러 입니다.
0
479
2





