Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to import images from public folder in react js 
Javascript :: when i add data into the input it disappeared in react 
Javascript :: Cannot coerce `dirty` to string because boolean [1] should not be coerced. 
Javascript :: blockchain.info/pushtx/ 
Javascript :: &amp;nbsp replace javascript 
Javascript :: how to render req.session.name to ejs 
Javascript :: date calendar show only icon click 
Javascript :: toggle value change inline angular 
Javascript :: nestjs run tests 
Javascript :: format JSON in VS 
Javascript :: jquery validate min and max value 
Javascript :: jquery remove array of classes 
Javascript :: react using props and parent state 
Javascript :: react extends component App.defaultProps 
Javascript :: Class Has a Constructor Function 
Javascript :: JS in JSX. Whenever you need to add some JS, just put it inside curly braces {} 
Javascript :: javascript Least prime factor of numbers till n 
Javascript :: _.template Underscore Example 
Javascript :: bun javascript runtime 
Javascript :: javascript foreach next iteration 
Javascript :: Component With Both Data And Props 
Javascript :: firebase database TIMESTAMP 
Javascript :: javascript custom table 
Javascript :: for loop increment by more than one 
Javascript :: how to add header to axios request 
Javascript :: javascript detect video change to muted 
Javascript :: how to get a set of values in mogodb 
Javascript :: node fs get size 
Javascript :: get time in between two dates javascript dayjs 
Javascript :: How to display html link inside table cell using reactjs material-table 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =