Answers for "how to auto update the local data after update / delete while using useSWR hook in React"

0

how to auto update the local data after update / delete while using useSWR hook in React

import useSWR, { useSWRConfig } from 'swr'

function App () {
  const { mutate } = useSWRConfig()

  return (
    <div>
      <Profile />
      <button onClick={() => {
        // set the cookie as expired
        document.cookie = 'token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'

        // tell all SWRs with this key to revalidate
        mutate('/api/user')
      }}>
        Logout
      </button>
    </div>
  )
}
Posted by: Guest on March-06-2022

Code answers related to "how to auto update the local data after update / delete while using useSWR hook in React"

Code answers related to "Javascript"

Browse Popular Code Answers by Language