title: Error retry strategy and function argument binding
body: <p>I'd like to make my swr state mutations resilient against network errors and support some kind of retry functionality.</p>
  <p>Basically what I do is inside my useSWR powered react hook:</p>
  <pre class="lang-js prettyprint-override"><code>const setFavourite = useCallback((objectId) =&gt; {
    const url = `/favs/${objectId}`
    const newData = [objectId, ...data]
    return mutate(newData, false)
      .then(() =&gt; request(&quot;POST&quot;, url))
      .then(() =&gt; mutate())
      .catch((error) =&gt; {
        mutate(data, false).catch(() =&gt; {})
        const userError = new Error(&quot;Could not add favourite&quot;)
        userError.retry = () =&gt; setFavourite(objectId)
      })
  }, [data, mutate, request])
  </code></pre>
  <p>I generate a new Error object with a <code>retry</code> function that can be used by the UI code to show a toast to retry the operation at later time (upon user interaction).</p>
  <p>I wonder if the dependencies to setFavourite are still valid at the time <code>retry()</code> would be called. I guess not, as they depend on <code>data</code> and if this changes, then the <code>setFavourite</code> is also regenerated.</p>
  <p>Anybody implemented such kind of retry before?</p>