swr 用于数据请求的 React Hooks 库

import useSWR from 'swr'

function Profile() {
  const { data, error, isLoading } = useSWR('/api/user', fetcher)

  if (error) return <div>failed to load</div>
  if (isLoading) return <div>loading...</div>
  return <div>hello {data.name}!</div>
}

 

官网地址:https://swr.bootcss.com/

posted @ 2024-07-11 09:28  红苹果学园  阅读(2)  评论(0编辑  收藏  举报