kiliman/remix-typedjson

Typed JSON while submitting data to the server?

Closed this issue · 2 comments

useTypedFetcher allows getting correctly typed data from the server to the frontend, however it does not seem to be helping when calling fetcher.submit with an object as the target? It feels like we could use the current encoding for "complex" values not only for receiving data, but also for sending data to the server?

Aha, looks like I can simply use the serialize and deserialize methods, like this:

export async function action({request}: ActionFunctionArgs) {
  const data = deserialize(await request.json());
}

export default Component() {
  const fetcher = useFetcher();
  fetcher.submit(serialize(myObject), {encType: "application/json"});
}

I was just going to comment on that. Glad you figured it out.