Open joeltio opened 1 month ago
This PR clarifies where data comes from under the section on mutations with optimistic data:
data
import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) const { data } = useSWR('/api/user', fetcher) // <--- Added return ( <div> <h1>My name is {data.name}.</h1> <button onClick={async () => { const newName = data.name.toUpperCase() trigger(newName, { optimisticData: user => ({ ...user, name: newName }), rollbackOnError: true }) }}>Uppercase my name!</button> </div> ) }
I have also added a short note under that code snippet to bring this to the reader's attention.
See also and closes https://github.com/vercel/swr/issues/2944
@joeltio is attempting to deploy a commit to the Vercel Team on Vercel.
A member of the Team first needs to authorize it.
This PR clarifies where
data
comes from under the section on mutations with optimistic data:I have also added a short note under that code snippet to bring this to the reader's attention.
See also and closes https://github.com/vercel/swr/issues/2944
Description