Hey,
Im struggling a bit with the hooks. I have a page at _app.$id.tsx which is actually an entity. On this page there is a delete button which itself is handle by an onclick event of its child components. Therefor the delete itself is just a function and not a form so i decided to pick the useSubmit handle. Feels all fine and it also works great. I have this code running:
const onListDeleteHandler = async (id: string) => {
const formData = new FormData();
formData.append("id", id);
submit(formData, { method: "post" });
};
And the action is handled like this:
export async function action({ request }: ActionArgs) {
const formData = await request.formData();
const data = Object.fromEntries(formData);
const result = await deleteById(data.id);
if (result) {
return redirect("/");
}
return json({
error: "Something went wrong here",
});
}
The question im having is, is this all fine and how can i catch the errors in the client that if a delete fails? At this moment is added a json return but ofc it is not doing much. Curious in valid patterns and workflows for this scenario.