Skip to content

Conversation

@pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Nov 6, 2025

This PR integrates Precognition into useForm(). We currently support this by installing the laravel-precognition-react-inertia or laravel-precognition-vue-inertia library and using the useForm() hook from those libraries. With this PR, that is no longer needed. We're bringing first-party support for Precognition.

For a smooth upgrade, you may use the existing parameters by passing the method and URL before the initial data. In that case, you only need to swap the useForm import from the Precognition library to @inertiajs/{react,svelte,vue3}.

const form = useForm('post', '/users', { name: '' })

If you're not using the Precognition library, you can enable Precognition on existing forms by simply chaining the withPrecognition() method.

const form = useForm({ name : '' }).withPrecognition('post', '/users')

When doing this, you no longer need to pass the method and URL to the submit() method, but you may still pass visit options.

const form = useForm({ name : '' }).withPrecognition('post', '/users')

form.submit()

form.submit({ preserveState: true })

There is now also full support for Wayfinder when using Precognition.

import { store, update } from 'App/Http/Controllers/UserController'

const createForm = useForm(store(), { name: '' })

const editForm = useForm({ ...user }).withPrecognition(update())

Other than instantiating the form instance, the API and behavior remain exactly the same.

<script setup lang="ts">
import { useForm } from '@inertiajs/vue3'

const form = useForm({
  name: ''
}).withPrecognition('post', '/users')
</script>

<template>
  <div>
    <input v-model="form.name" @blur="form.validate('name')" />

    <p v-if="form.invalid('name')">
      {{ form.errors.name }}
    </p>

    <p v-if="form.valid('name')">Name is valid!</p>
  </div>
</template>

And for the first time, we now also have support for Svelte!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants