Skip to content

[3.0] Fix React useForm submitting stale data after synchronous setData#3057

Open
skryukov wants to merge 1 commit intoinertiajs:3.xfrom
skryukov:fix-react-useform-using-stale-data
Open

[3.0] Fix React useForm submitting stale data after synchronous setData#3057
skryukov wants to merge 1 commit intoinertiajs:3.xfrom
skryukov:fix-react-useform-using-stale-data

Conversation

@skryukov
Copy link
Copy Markdown
Contributor

@skryukov skryukov commented Apr 10, 2026

In the React adapter, calling setData() (or reset()) and then immediately submitting the form in the same event handler submits the pre-update data, not the value just written.

const { data, setData, post } = useForm({ code: '' })

onChange={(value) => {
  setData('code', value)
  if (value.length === 6) {
    post('/verify-otp') // submits the *previous* value ❌
  }
}}

Root cause: submit() reads form data from dataRef.current, but dataRef is only refreshed inside a post-commit useEffect. Vue and Svelte are unaffected.

See inertiajs/inertia-rails#300

@skryukov skryukov changed the title Fix React useForm submitting stale data after synchronous setData [3.0] Fix React useForm submitting stale data after synchronous setData Apr 10, 2026
@skryukov skryukov marked this pull request as ready for review April 10, 2026 20:40
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.

1 participant