useDebugValue - rs-hash/Learning GitHub Wiki
-
useDebugValue:
- Description: useDebugValue is used to display a label for custom hooks in React DevTools.
- Example:
import { useDebugValue, useState } from 'react'; function useCustomHook(initialValue) { const [value, setValue] = useState(initialValue); useDebugValue(value > 0 ? 'Positive' : 'Negative'); return value; }
Explanation: In the example above, the
useDebugValuehook is used within a custom hook. When the hook is inspected in React DevTools, it will display either 'Positive' or 'Negative' based on the value. This can be helpful for providing additional debugging information for custom hooks.