Skip to content

Commit

Permalink
Added optional formatting function param
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 17, 2019
1 parent 8041867 commit 2ea796e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ declare module react {

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

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

declare export function useEffect(
create: () => MaybeCleanUpFn,
Expand Down
24 changes: 21 additions & 3 deletions tests/react/useDebugValue_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@

import React from 'react';

const undefinedValue = React.useDebugValue(123);
{
// 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});
}

(undefinedValue: typeof undefined); // Ok
(undefinedValue: string); // Error: undefined is incompatible with string
{
// Has an undefined return type
((React.useDebugValue(123)): typeof undefined);
}

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

0 comments on commit 2ea796e

Please sign in to comment.