Skip to content
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

[react] Add typing for useTransition config in react/next #58421

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion types/react/next.d.ts
Expand Up @@ -70,6 +70,15 @@ declare module '.' {
*/
export function useDeferredValue<T>(value: T): T;

export interface useTransitionConfig {
/**
* This timeout (in milliseconds) tells React how long to wait before showing the next state
*
* @see https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
*/
timeoutMs?: number | undefined;
}

/**
* Allows components to avoid undesirable loading states by waiting for content to load
* before transitioning to the next screen. It also allows components to defer slower,
Expand All @@ -87,7 +96,7 @@ declare module '.' {
*
* @see https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
*/
export function useTransition(): [boolean, TransitionStartFunction];
export function useTransition(config?: useTransitionConfig): [boolean, TransitionStartFunction];

/**
* Similar to `useTransition` but allows uses where hooks are not available.
Expand Down
4 changes: 3 additions & 1 deletion types/react/test/next.tsx
Expand Up @@ -29,7 +29,9 @@ const subscribe: React.MutableSourceSubscribe<Window> = (window, callback) => {
function useExperimentalHooks() {
const [toggle, setToggle] = React.useState(false);

const [done, startTransition] = React.useTransition();
React.useTransition();
React.useTransition({});
const [done, startTransition] = React.useTransition({ timeoutMs: 1000 });
// $ExpectType boolean
done;

Expand Down