koba04 / swr-devtools

A DevTool for SWR
https://swr-devtools.vercel.app
MIT License
217 stars 3 forks source link

feat: record SWR data with useDebugValue #37

Open koba04 opened 2 years ago

koba04 commented 2 years ago

useDebugValue can be used to display values in React Developer Tools. This PR is to add useDebugValue in SWR DevTools middleware to display SWR data.

image
vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/koba04/swr-devtools/mSAcapc39bwByCihTddo1wNvEmfK
✅ Preview: https://swr-devtools-git-feat-record-swr-data-with-usedebugvalue-koba04.vercel.app

koba04 commented 2 years ago

I've noticed that this approach might have extra re-render because SWR tracks the usage of the response data by getter functions. https://github.com/vercel/swr/blob/98556e12d394c819fd69535ad5fe0dd980e79fe9/src/use-swr.ts#L487-L501

This code would mark the data as used even if the actual implementation didn't access the data.