useDateFieldState
Provides state management for a date field component. A date field allows users to enter and edit date and time values using a keyboard. Each part of a date value is displayed in an individually editable segment.
| install | yarn add react-stately | 
|---|---|
| version | 3.42.0 | 
| usage | import {useDateFieldState} from 'react-stately' | 
API#
useDateFieldState<T extends DateValue = DateValue>(
  (props: DateFieldStateOptions<T>
)): DateFieldState
Interface#
Properties
| Name | Type | Description | 
| value | DateValue | null | The current field value. | 
| defaultValue | DateValue | null | The default field value. | 
| dateValue | Date | The current value, converted to a native JavaScript Dateobject. | 
| calendar | Calendar | The calendar system currently in use. | 
| segments | DateSegment[] | A list of segments for the current value. | 
| dateFormatter | DateFormatter | A date formatter configured for the current locale and format. | 
| isInvalid | boolean | Whether the date field is invalid, based on the isInvalid,minValue, andmaxValueprops. | 
| granularity | Granularity | The granularity for the field, based on the granularityprop and current value. | 
| maxGranularity | 'year'
  | 'month'
  | Granularity | The maximum date or time unit that is displayed in the field. | 
| isDisabled | boolean | Whether the field is disabled. | 
| isReadOnly | boolean | Whether the field is read only. | 
| isRequired | boolean | Whether the field is required. | 
| realtimeValidation | ValidationResult | Realtime validation results, updated as the user edits the value. | 
| displayValidation | ValidationResult | Currently displayed validation results, updated when the user commits their changes. | 
Methods
| Method | Description | 
| setValue(
  (value: DateValue
    |  | null
)): void | Sets the field's value. | 
| increment(
  (type: SegmentType
)): void | Increments the given segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. | 
| decrement(
  (type: SegmentType
)): void | Decrements the given segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. | 
| incrementPage(
  (type: SegmentType
)): void | Increments the given segment by a larger amount, rounding it to the nearest increment. The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. | 
| decrementPage(
  (type: SegmentType
)): void | Decrements the given segment by a larger amount, rounding it to the nearest increment. The amount to decrement by depends on the field, for example 15 minutes, 7 days, and 5 years. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. | 
| setSegment(
  (type: SegmentType,
  , value: number
)): void | Sets the value of the given segment. | 
| confirmPlaceholder(): void | Updates the remaining unfilled segments with the placeholder value. | 
| clearSegment(
  (type: SegmentType
)): void | Clears the value of the given segment, reverting it to the placeholder. | 
| formatValue(
  (fieldOptions: FieldOptions
)): string | Formats the current date value using the given options. | 
| getDateFormatter(
  (locale: string,
  , formatOptions: FormatterOptions
)): DateFormatter | Gets a formatter based on state's props. | 
| updateValidation(
  (result: ValidationResult
)): void | Updates the current validation result. Not displayed to the user until commitValidationis called. | 
| resetValidation(): void | Resets the displayed validation state to valid when the user resets the form. | 
| commitValidation(): void | Commits the realtime validation so it is displayed to the user. | 
Example#
See the docs for useDateField in react-aria for an example of useDateFieldState.