Skip to content

chore: export useControlledState from react-stately and react-aria-components #8620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@react-stately/utils/src/useControlledState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

import {useCallback, useEffect, useRef, useState} from 'react';

/**
* Provides state management for controlled and uncontrolled values.
*
* @param value - The controlled value. Pass `undefined` to make the component uncontrolled.
* @param defaultValue - The initial value when uncontrolled.
* @param onChange - Callback fired whenever the value changes.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param onChange - Callback fired whenever the value changes.
* @param onChange - Callback fired whenever the value changes.
* @returns [value, (val) => void] - something here about how we don't support the prevState callback on setState?

*/
export function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];
export function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void];
export function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: T, ...args: any[]) => void] {
Expand Down
1 change: 1 addition & 0 deletions packages/react-aria-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export {DIRECTORY_DRAG_TYPE, isDirectoryDropItem, isFileDropItem, isTextDropItem
export {FormValidationContext, parseColor, getColorChannels, ToastQueue as UNSTABLE_ToastQueue} from 'react-stately';
export {ListLayout, GridLayout, WaterfallLayout} from '@react-stately/layout';
export {Layout, LayoutInfo, Size, Rect, Point} from '@react-stately/virtualizer';
export {useControlledState} from '@react-stately/utils';

export type {AutocompleteProps} from './Autocomplete';
export type {BreadcrumbsProps, BreadcrumbProps, BreadcrumbRenderProps} from './Breadcrumbs';
Expand Down
1 change: 1 addition & 0 deletions packages/react-stately/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@react-stately/toggle": "^3.9.0",
"@react-stately/tooltip": "^3.5.6",
"@react-stately/tree": "^3.9.1",
"@react-stately/utils": "^3.10.8",
"@react-types/shared": "^3.31.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/react-stately/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export {useToggleState, useToggleGroupState} from '@react-stately/toggle';
export {useTooltipTriggerState} from '@react-stately/tooltip';
export {useTreeState} from '@react-stately/tree';
export {FormValidationContext} from '@react-stately/form';
export {useControlledState} from '@react-stately/utils';
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26299,6 +26299,7 @@ __metadata:
"@react-stately/toggle": "npm:^3.9.0"
"@react-stately/tooltip": "npm:^3.5.6"
"@react-stately/tree": "npm:^3.9.1"
"@react-stately/utils": "npm:^3.10.8"
"@react-types/shared": "npm:^3.31.0"
peerDependencies:
react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1
Expand Down
Loading