Skip to content

[FEATURE] add previous state to useInputState transform function #553

Closed

Description

@Antoliny0919

Is your feature request related to a problem? Please describe.

Currently, the transform function in useInputState only receives the new input value. To preserve the current value when the input exceeds a length limit, the transform function needs to reference the hook’s return value. (example)

const [nameValue, handleNameValue] = useInputState(
  initialValues.name,
  value => {
    if (value.length > STUDY_NAME.length) {
      return nameValue;
    }

    return value;
  }
);

However, this pattern triggers the following ESLint error when the react-hooks/immutability rule is enabled.

Error: Cannot access variable before it is declared

This makes it difficult to define input rules that depend on the previous state directly within the transform function.

Describe the solution you'd like

Allow the transform function to receive the state immediately before the update as its second argument.
like this ...

const [nameValue, handleNameValue] = useInputState(
  initialValues.name,
  (value, previousValue) => {
    if (value.length > STUDY_NAME.length) {
      return previousValue;
    }

    return value;
  }
);

This would allow the transform function to reject an input change by returning previousValue, without referencing the hook’s own return value. Existing single argument transform functions would remain compatible.

Describe alternatives you've considered

If there’s a better approach, please let me know.

Additional context

A length limit is one example of an input rule that benefits from access to the previous state.
The same approach could support other validation rules that need to preserve the previous value when an input change is rejected.

If this proposal is accepted, could you assign this issue to me?

Activity

  1. hyesungoh commented on Oct 14, 2026

    @hyesungoh
    Member

    I think it's good! 👍 Can you do this?

  2. Antoliny0919 commented on Oct 14, 2026

    @Antoliny0919
    ContributorAuthor

    I think it's good! 👍 Can you do this?

    I think my colleague will handle it @DongEun02 😁

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions