inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

풀스택 리액트 라이브코딩 - 간단한 쇼핑몰 만들기

index.tsx에서 ProductItem부분에서 해당 반환 형식이 유효하지 않다고 할 때

해결된 질문

475

givita_dev

작성한 질문수 3

0

index.tsx에서 ProductItem부분에서 해당 반환 형식이 유효하지 않다고 하면서 화면에 Display되지 않을때 어디를 확인하면 되는지 조언 부탁드립니다~

데이터는 BASE_URL로 부터 잘 오고 있습니다

mac에서 vsc사용하고 있습니다

아래는 해당부분입니다

import { useQuery } from "react-query"
import ProductItem from "../../components/product/item"
import { fetcher, QueryKeys } from "../../queryClient"
import {Product} from "../../types"

const ProductList = () => {
    const {data} = useQuery<Product[]>(QueryKeys.PRODUCTS, () => 
        fetcher({
            method: 'GET',
            path: '/products'
        }),
    )


    /*
    id: 1
    title: "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops"
    price: 109.95
    description: "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday"
    category: "men's clothing"
    image: "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg"
    ▶ rating 2 items
    rate: 3.9
    count: 120
    */

    return (
        <div>
            <ul>
                {data?.map(product => (
                    <ProductItem {...product} key={product.id} />
                ))}
            </ul>
        </div>
    )

    //return (<div>상품목록</div>)
}
export default ProductList

components/product/item.tsx 파일입니다

graphql firebase react

답변 2

1

정재남

ProductItem의 화살표 우측은 중괄호 { 가 아닌 괄호 ( 입니다.

arrow function의 내용이 return만 있을 경우에는 중괄호 없이 return할 내용만 적으면 되거든요.

0

givita_dev

네~~~감사합니다^__^

1

givita_dev

import { Product } from "../../types"

const ProductItem = ({ id, category, description, image, price, rating, title}: Product) => {
    return <>
        <li>
            <p>{category}</p>
            <p>{title}</p>
            <p>{description}</p>
            <img src={image} />
            <span>${price}</span>
            <span>{rating.rate}</span>
        </li>
    </>
}

export default ProductItem

 

void가 안된다기에 item.tsx내 return으로 감싸고 id를 추가하니 화면에 잘 렌더링 되었습니다~

장바구니 담기 버튼 누르면 404에러가 뜹니다

0

255

1

[useRoutes, React-Query 오류 해결방법] No QueryClient set, use QueryClientProvider to set one 에러 나시는 분 보세요 !!!

4

1210

2

깃허브에서 선생님께서 올리신 파일 받아,, 실행시켜보려했으나 안됩니다

0

343

1

상품목록페이지만들기에서 ... 막힙니다..

0

407

1

강의 시점과 지금시점이 꽤 달라진게 있는거 같아요

0

501

1

상품목록 불러오기, 장바구니 삭제 에러 질문 드립니다

0

411

1

graphqlFetcher 관련 에러와 , data 객체 정의 되지 않는 오류 질문 드립니다

0

572

2

productdetail 데이터 안불러와지고 있습니다.

1

446

1

query 에러 발생했습니다.

1

538

1

react typescript vite 설치시 오류 질문드립니다.

0

1794

2

섹션1의 1강 routes.tsx에서 에러가 발생합니다

0

813

2

routes.tsx에서 질문이 있습니다!

1

576

1

vite-plugin-next-react-router

0

1476

3

grahpqlFetcher 설명가능할까요

1

501

1

msw mocking enabled

1

790

2

[기술 질문아님]

0

551

2

products 라우팅은 되는데 cart 라우팅은 안되네요 ㅠ

0

586

2

caught Error: No QueryClient set, use ueryClientProvider 에러

13

1970

3

Heroku build관련 오류가 발생해 글 남깁니다 ㅠㅠ

0

706

1

firebase filterling 관련 질문

0

569

3

body가 json 형태가 아닌 ReadableStream 형태로 찍힙니다.

0

785

1

graphqlFetcher 관련 에러가 해결이 안됩니다. ㅠㅠ

1

673

3

MSW graphqlFetcher 에러 관련

0

478

1

graphql-tag, graphql-request 패키지를 사용하는 이유가 궁금합니다.

0

791

1