Skip to content
Source
Sign inSign up
TanStack/form

[v2] Expose the previous value to change listeners #2301

OpenLeCarbonator(GitHub profile, opens in a new tab) opened this issue 0 comments

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.

  1. LeCarbonator(GitHub profile, opens in a new tab) added labelstype: enhancement

  2. LeCarbonator(GitHub profile, opens in a new tab) added labelsscope: core

  3. LeCarbonator(GitHub profile, opens in a new tab) added labelsarea: runtime

  4. LeCarbonator(GitHub profile, opens in a new tab) added labelsarea: types

Sign in to join this conversation.