BFE.dev
React コーディング問題4. useSWR() I

4. useSWR() I

ReactHooks
シェアしよう

  - accepted / - tried

SWR is a popular library of data fetching.

Let's try to implement the basic usage by ourselves.

import React from 'react'function App() {  const { data, error } = useSWR('/api', fetcher)  if (error) return <div>failed</div>  if (!data) return <div>loading</div>  return <div>succeeded</div>}
  1. this is not to replicate the true implementation of useSWR()
  2. The first argument key is for deduplication, we can safely ignore it for now
前へ次へ

バッグフリーで普通なコードは何より。

解答AI投稿(108)

Try it out

Console