Posts

Showing posts from August, 2023

react-router data router submit nested json data

This topic is a hot one and has resulted in a long thread: https://github.com/remix-run/remix/discussions/1959 and remix discord questions lik: "how can i use useFetcher to submit a big nested JSON object to an action (via POST without a backing <fetcher.Form> component)? it seems like fetcher.submit only accepts Record<string, string>." Answer: "You can JSON.stringify the data and JSON.parse it on the action" Support to submit json data was added to react-router DataRouter, but only un-nested json e.g. { name: "jane", hair: "purple" } But not nested: { name: "jane", hair: "purple", address: { street: " 1 Main St."} } Which is the key missing piece. So you can now do this     fetcher.submit(       { action: 'save', name: "jane", hair: "purple"  },       { method: 'post', encType: "application/json", action: "/" }     );  and in the action function g