Skip to content

Commit

Permalink
Add docs for useDebugValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 15, 2019
1 parent 165ae04 commit 4c29b69
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions content/docs/hooks-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ If you're new to Hooks, you might want to check out [the overview](/docs/hooks-o
- [`useRef`](#useref)
- [`useImperativeMethods`](#useimperativemethods)
- [`useLayoutEffect`](#uselayouteffect)
- [`useDebugValue`](#usedebugvalue)

## Basic Hooks

Expand Down Expand Up @@ -353,3 +354,31 @@ Prefer the standard `useEffect` when possible to avoid blocking visual updates.
> Tip
>
> If you're migrating code from a class component, `useLayoutEffect` fires in the same phase as `componentDidMount` and `componentDidUpdate`, so if you're unsure of which effect Hook to use, it's probably the least risky.
### `useDebugValue`

```js
useDebugValue(value)
```

`useDebugValue` can be used to provide a label for the React DevTools to display beside of a custom hook.

For example, consider the `useFriendStatus` custom hook described in ["Building Your Own Hooks"](/docs/hooks-custom.html):

```js{6-8}
function useFriendStatus(friendID) {
const [isOnline, setIsOnline] = useState(null);
// ...
// Show a label in DevTools beside of this hook
// e.g. "FriendStatus: Online"
useDebugValue(isOnline ? 'Online' : 'Offline');
return isOnline;
}
```

> 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.

0 comments on commit 4c29b69

Please sign in to comment.