Skip to content

Commit

Permalink
Added useDebugValue formatter function
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 17, 2019
1 parent 26b0eb2 commit 0ace70f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions content/docs/hooks-reference.md
Expand Up @@ -384,3 +384,14 @@ function useFriendStatus(friendID) {
> Tip
>
> We don't recommend adding debug values to every custom hook. It's most valuable for custom hooks that are part of shared libraries.
#### Defer formatting debug values

In some cases formatting a value for display might be an expensive operation. It's also unnecessary unless a hook is actually inspected.

For this reason `useDebugValue` accepts a formatting function as an optional second parameter. This function is only called if the hooks is inspected. It receives the debug value as a parameter and should return a formatted display value.

For example a custom hook that returned a `Date` value could avoid calling the `toDateString` function unnecessarily by passing the following formatter:
```js
useDebugValue(date, date => date.toDateString());
```

0 comments on commit 0ace70f

Please sign in to comment.