forge42dev / remix-hook-form

Open source wrapper for react-hook-form aimed at Remix.run
MIT License
330 stars 27 forks source link

Export generateFormData function #90

Closed kveperedo closed 1 month ago

kveperedo commented 5 months ago

Description

This change exports the generateFormData function.

When implementing optimistic ui via useFetcher, we need to get the parsed data from fetcher.formData. We cannot use parseFormData because it returns a promise but it's possible if we use the generateFormData function which is not async.

const fetcher = useFetcher();

// This should have the correct json data for optimistic ui
const pendingItems = fetcher.formData ? generateFormData(fetcher.formData) : null

This should also partially resolve this discussion: https://github.com/Code-Forge-Net/remix-hook-form/discussions/24

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Checklist: