Skip to content

Instantly share code, notes, and snippets.

@4lun
4lun / useAPIForm.ts
Last active August 29, 2025 14:05
A (React) utility hook that is a drop in replacement for the useForm hook from Inertia.js, but for use with general API endpoints. Any page updates or navigation needs to be handled manually via onSuccess callback.
/**
* A utility hook that is a drop in replacement for the useForm hook from
* Inertia.js, for use with general API endpoints. Any page updates or
* navigation needs to be handled manually via onSuccess callback.
*
* Author: https://github.com/4lun
* Source: https://gist.github.com/4lun/b91cdc4b82c1ff3b5506b47cb29dcfd4
*
* Based on a combination of
* - https://gist.github.com/mohitmamoria/91da6f30d9610b211248225c9e52bebe
@mohitmamoria
mohitmamoria / README.md
Last active October 19, 2025 02:39
Inertia.js Form Helper for Axios/API calls

Inertia.js ships with a fantastic form helper but it falls short when also using API/Axios calls in your project.

Here's a composable, built on top of the Inertia's form helper that hooks into it to replace the API calls with Axios.

To use, just replace useForm with useAPIForm.

const form = useAPIForm({
    title: '',
});