vercel/swr ? reverse-engineered prompt

Reverse engineered prompt

Build me a React hook library for data fetching that works the way SWR does.

I want one simple hook that takes a request key and a fetch function, then gives back loading, data, and error states. It should use cache so it can show old data right away, then refresh in the background and update the UI when the new data arrives. Please include smart request sharing so the same request does not get fired twice, plus automatic refresh when the user comes back to the tab or the network reconnects. It should also support polling, pagination, optimistic updates, retry on errors, suspense, server rendering, and React Native friendly usage.

Make it clean, fast, and easy to use in TypeScript, with a few simple examples and tests. If anything is unclear, look up the current docs online and follow the common behavior people expect from SWR.

Are you gonna build this?

make sure you review the code using coderabbit

Try freeSponsored — opens CodeRabbit in a new tab