Skip to content

[refactor] rework useInputState#416

Merged
severo merged 2 commits intomasterfrom
controlled-uncontrolled
Feb 4, 2026
Merged

[refactor] rework useInputState#416
severo merged 2 commits intomasterfrom
controlled-uncontrolled

Conversation

@severo
Copy link
Copy Markdown
Contributor

@severo severo commented Feb 4, 2026

Delete useInputOrDisabledState, replace with local logic in SelectionProvider (it was used only there)

Add type: 'controlled' | 'uncontrolled' in useInputState result. It will help to know if we can update the DOM (scroll, focus) optimistically, or if we should react using useEffect.

Add/update doc strings.

@severo severo changed the title [refactor] [refactor] rework useInputState Feb 4, 2026
@severo severo requested a review from Copilot February 4, 2026 22:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the useInputState hook by removing the useInputOrDisabledState wrapper and moving its disabled-state logic directly into SelectionProvider. The hook now returns a discriminated union type that explicitly indicates whether the input is controlled or uncontrolled, which will help consumers determine when they can perform optimistic DOM updates.

Changes:

  • Deleted useInputOrDisabledState hook and replaced it with local isEnabled state logic in SelectionProvider
  • Added type: 'controlled' | 'uncontrolled' field to useInputState return type using discriminated unions
  • Renamed parameters for clarity: valuecontrolledValue, defaultValueinitialUncontrolledValue
  • Updated and expanded documentation strings

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/hooks/useInputState.ts Removed useInputOrDisabledState, added discriminated union type with type field, renamed parameters, improved documentation
src/providers/SelectionProvider.tsx Replaced useInputOrDisabledState with useInputState plus local isEnabled logic, updated parameter names
src/providers/OrderByProvider.tsx Updated to use new parameter names (controlledValue, initialUncontrolledValue)
test/hooks/useInputState.test.ts Removed tests for useInputOrDisabledState, updated remaining tests to use new parameter names and verify type field

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

type: 'controlled'
/** the current input value */
value: T
/** the callback to call when the input changes. If undefined, the user interactions (or optimistical updates) should be disabled. */
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "optimistical" should be "optimistic".

Suggested change
/** the callback to call when the input changes. If undefined, the user interactions (or optimistical updates) should be disabled. */
/** the callback to call when the input changes. If undefined, the user interactions (or optimistic updates) should be disabled. */

Copilot uses AI. Check for mistakes.
Comment thread src/hooks/useInputState.ts Outdated
@severo severo merged commit 5f44a55 into master Feb 4, 2026
5 checks passed
@severo severo deleted the controlled-uncontrolled branch February 4, 2026 22:51
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