cossack910 / reactAd

レンダリング、CSS、ルーティング
0 stars 0 forks source link

axios #7

Open cossack910 opened 1 year ago

cossack910 commented 1 year ago

install

types無しで型提供あり。

docker exec -it reactad npm install axios
cossack910 commented 1 year ago

axiosの型定義

json https://jsonplaceholder.typicode.com/comments
interface

interface CommentType {
  postId: number;
  id: number;
  name: string;
  email: string;
  body: string;
}


axios

axios
      .get<Array<CommentType>>("https://jsonplaceholder.typicode.com/comments")
      .then((res) => {
        setComment(res.data);
      })
      .catch(() => {
        console.log("error");
      });