#Working with formdata and nested objects

1 messages · Page 1 of 1 (latest)

opaque pollen
#

Is there a convenient way of working with formdata in an action. I have an object

type MyData = {
somename:string;
subObjects[]: {
name:string;
address;
}
}

But when retrieving in an action it looks like i have to do some massive parsing to get this working
subObjects[0].name ="asdfasf"

Is what I have, is this an anti-pattern. Are there no libraries to take my formData to my desired object? Is it "frowned" upon to just submit it as JSON?

React router 7

languid dock
opaque pollen
#

thanks, I will check it out. Eventually I found "parse-nested-form-data" but that looks more professional 😄

languid dock
#

Perhaps worth noting that the problem of complex data in forms isn't unique to React Router. They've hung their hat on fundamental web tech (forms) but don't come with any opinions about how to structure your form and its data. Conform is a good way to add functionality to a basic form.

I also wouldn't say that using useSubmit and constructing some JSON to send is an anti-pattern. Some forms and data are just going to be too unique for a form to handle on its own. I'd always start with trying to use a basic form and only adapt from it if it's feeling forced.