mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Inspectable complex hook values
This commit is contained in:
@@ -11,6 +11,16 @@ import React, {
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
const object = {
|
||||
string: 'abc',
|
||||
number: 123,
|
||||
boolean: true,
|
||||
null: null,
|
||||
undefined: undefined,
|
||||
array: ['a', 'b', 'c'],
|
||||
object: { foo: 1, bar: 2, baz: 3 },
|
||||
};
|
||||
|
||||
function useNestedInnerHook() {
|
||||
return useState(123);
|
||||
}
|
||||
@@ -18,12 +28,20 @@ function useNestedOuterHook() {
|
||||
return useNestedInnerHook();
|
||||
}
|
||||
|
||||
function useCustomObject() {
|
||||
useDebugValue(object);
|
||||
return useState(123);
|
||||
}
|
||||
|
||||
function FunctionWithHooks(props: any, ref: React$Ref<any>) {
|
||||
const [count, updateCount] = useState(0);
|
||||
const [_, __] = useState(object);
|
||||
|
||||
// Custom hook with a custom debug label
|
||||
const debouncedCount = useDebounce(count, 1000);
|
||||
|
||||
useCustomObject();
|
||||
|
||||
const onClick = useCallback(
|
||||
function onClick() {
|
||||
updateCount(count + 1);
|
||||
|
||||
Reference in New Issue
Block a user