TanStack / TanStack/form

[v2] Expose the previous value to change listeners

Open
#2,301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: runtime area: types scope: core type: enhancement v2
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

onChange listeners may need to compare the current form value with the value immediately before the change. The listener context could support this by exposing an optional prevValue property:

prevValue?: TData

For a change event, prevValue would contain the value before that change was applied. It would not be present for other listener events.

Debounced listeners

The previous value should correspond to the specific change that ultimately invokes the listener. For example, if a debounced change listener receives five changes in quick succession, the callback would run after the timeout with the fourth value as prevValue and the fifth as the current value.

Some thoughts

setFieldValue and handleChange could capture the previous value and pass that snapshot through the listener context. The property needs to remain optional because the shared listener context is also used by events that are not change events.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing setFieldValue and handleChange into the shared listener context and the debounced change-listener path. Add coverage showing prevValue is the value before the specific change, including debounced successive changes, and that it is absent for non-change events.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.