vercel-labs / next-fetch

Intuitive data fetching for Next.js
https://next-fetch-pi.vercel.app/
589 stars 14 forks source link

experiment: allow custom http responses for non-swr requests #13

Closed Schniz closed 2 years ago

Schniz commented 2 years ago

This experiment enables defining a custom HTTP response resolution for requests that aren't made by the use... hooks created by the library.

This allows people to re-use the logic in forms, which mean that people can have progressive enhancement in their forms: if JS is not loaded, you can submit the form "as is", and once JS is loaded, you will fire an SWR mutation request. I think it's cool.

The only thing I'm not sure about is the API. This commit enables the following API:

export const useMyMutation = mutation(parser, async () => output, {
  async resolveFormSubmission(output) {
    return new Response(...)
  }
})

This makes sense, but:

  1. not every direct request is a form submission
  2. how do we create form tags out of this?

This issue always provides a useForm(mutationHook): { formProps } function that eases form creation by returning the props necessary for forms to be used with SWR mutations for progressive enhancement

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
next-swr-endpoints-example-app ✅ Ready (Inspect) Visit Preview Aug 8, 2022 at 8:21AM (UTC)