강의

멘토링

로드맵

Inflearn コミュニティ Q&A

lepetit807427 のプロフィール画像
lepetit807427

投稿した質問数

TypeScriptで学ぶReact.js:基礎から最新技術まで完璧に

useOptimistic 実践 - 1

useOptimistic 실전-1 useState

作成

·

41

0

import axios from "axios";
import { Heart } from "lucide-react";
import { useEffect, useState, useTransition } from "react";

interface Posts {
  id: number;
  isLike: boolean;
}

export default function App() {
  const [posts, setPosts] = useState<Posts[]>([]);
  const [isPending, startTransition] = useTransition();

  useEffect(() => {
    startTransition(async () => {
      const { data } = await axios.get("http://localhost:3000/posts");
      setPosts(data);
    });
  }, []);

  if (isPending) return <h3>loading..</h3>;

  return (
    <>
      {/* fill: 'none', stroke: 'currentColor' */}
      {/* fill: 'rgb(255,0,0)', stroke: 'rgb(255,0,0)' */}

      {posts.map((post) => {
        <Heart
          key={post.id}
          fill={post.isLike ? "rgb(255,0,0)" : "none"}
          stroke={post.isLike ? "rgb(255,0,0)" : "currentColor"}
        />;
      })}
    </>
  );
}
image.png

 

 

posts에 값이 설정되지 않는데요. 이런 경우가 처음이라 다른 예제는 이런 적이 없었습니다.

몇 시간에 해보는데 뭐가 잘못되었는지 잘 모르겠네요.

reactreact-routerredux-toolkitzustandreact.js

回答 2

0

sucoding님의 프로필 이미지
sucoding
インストラクター

안녕하세요.

해결하셨다니 다행입니다. 😀

0

lepetit807427님의 프로필 이미지
lepetit807427
質問者

<Heart key={post.id} fill={post.isLike ? "rgb(255,0,0)" : "none"} stroke={post.isLike ? "rgb(255,0,0)" : "currentColor"} />;

마지막 ; 이게 문제였습니다. 프리티어가 자꾸 ; 붙여줘서 그랬네요.

lepetit807427 のプロフィール画像
lepetit807427

投稿した質問数

質問する