diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index 45b7a177de..eaf108fee1 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -24,6 +24,7 @@ declare namespace React { export import useDebugValue = _hooks.useDebugValue; export import useEffect = _hooks.useEffect; export import useImperativeHandle = _hooks.useImperativeHandle; + export import useId = _hooks.useId; export import useLayoutEffect = _hooks.useLayoutEffect; export import useMemo = _hooks.useMemo; export import useReducer = _hooks.useReducer; diff --git a/hooks/src/index.d.ts b/hooks/src/index.d.ts index 7b42d69fda..dfec612eaa 100644 --- a/hooks/src/index.d.ts +++ b/hooks/src/index.d.ts @@ -138,4 +138,4 @@ export function useErrorBoundary( callback?: (error: any, errorInfo: ErrorInfo) => Promise | void ): [any, () => void]; -export function useId(): string; +export function useId(): string; diff --git a/hooks/src/index.js b/hooks/src/index.js index 5dbcc0bac9..cff822c062 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -41,13 +41,13 @@ options._diff = vnode => { // this is the first component rendered and hasn't been seen, it's a root: vnode._mask = mask = ''; } else { - // replace mask[depth] with the next character: (basically *mask[depth-1]++) + // replace mask[depth] with the next: (basically *mask[depth-1]++) const offset = Number(mask[depth - 1]) + 1; vnode._mask = mask = mask.slice(0, depth - 1) + offset; } - // we're about to render the children of this component, push a new level onto the mask: + depth++; - mask += '0'; // next level starts off at the base character (code 65) again + mask += '0'; } currentComponent = null; @@ -85,7 +85,6 @@ options.diffed = vnode => { if (oldAfterDiff) oldAfterDiff(vnode); if (typeof vnode.type === 'function' && vnode.type !== Fragment) { - // jump back up the stack, remove the last char from the mask: depth--; mask = mask.slice(0, -1); }