You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/hooks-reference.md
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -384,3 +384,14 @@ function useFriendStatus(friendID) {
384
384
> Tip
385
385
>
386
386
> We don't recommend adding debug values to every custom hook. It's most valuable for custom hooks that are part of shared libraries.
387
+
388
+
#### Defer formatting debug values
389
+
390
+
In some cases formatting a value for display might be an expensive operation. It's also unnecessary unless a hook is actually inspected.
391
+
392
+
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.
393
+
394
+
For example a custom hook that returned a `Date` value could avoid calling the `toDateString` function unnecessarily by passing the following formatter:
0 commit comments