Conversation
…ed' | 'uncontrolled' in useInputState
Contributor
There was a problem hiding this comment.
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
useInputOrDisabledStatehook and replaced it with localisEnabledstate logic inSelectionProvider - Added
type: 'controlled' | 'uncontrolled'field touseInputStatereturn type using discriminated unions - Renamed parameters for clarity:
value→controlledValue,defaultValue→initialUncontrolledValue - 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. */ |
There was a problem hiding this comment.
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. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.