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

Add definitions for new debug hook useDebugValue #7356

Closed
wants to merge 2 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
5 changes: 5 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ declare module react {

declare export function useRef<T>(initialValue: ?T): {current: T | null};

declare export function useDebugValue(
value: any,
formatterFn: ?(value: any) => any,
): void;

declare export function useEffect(
create: () => MaybeCleanUpFn,
inputs: ?$ReadOnlyArray<mixed>,
Expand Down
26 changes: 26 additions & 0 deletions tests/react/useDebugValue_hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @flow

import React from 'react';

{
// Accepts any type of value
React.useDebugValue('abc');
React.useDebugValue(123);
React.useDebugValue(true);
React.useDebugValue(['a','b','c']);
React.useDebugValue({foo: 1, bar: 2});
}

{
// Has an undefined return type
((React.useDebugValue(123)): typeof undefined);
}

{
// Supports optional formatting function
const date = new Date();
React.useDebugValue(
date,
date => date.toDateString(),
);
}