GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — useId (#22644) · react/react@ebf9ae8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-debug-tools/src
      • ReactDebugHooks.js
      • __tests__
        • ReactHooksInspectionIntegration-test.js
    • react-dom/src
      • __tests__
        • ReactDOMUseId-test.js
      • server
        • ReactPartialRendererHooks.js
    • react-reconciler/src
      • ReactChildFiber.new.js
      • ReactChildFiber.old.js
      • ReactFiberBeginWork.new.js
      • ReactFiberBeginWork.old.js
      • ReactFiberCompleteWork.new.js
      • ReactFiberCompleteWork.old.js
      • ReactFiberFlags.js
      • ReactFiberHooks.new.js
      • ReactFiberHooks.old.js
      • ReactFiberHydrationContext.new.js
      • ReactFiberHydrationContext.old.js
      • ReactFiberLane.new.js
      • ReactFiberLane.old.js
      • ReactFiberSuspenseComponent.new.js
      • ReactFiberSuspenseComponent.old.js
      • ReactFiberTreeContext.new.js
      • ReactFiberTreeContext.old.js
      • ReactFiberUnwindWork.new.js
      • ReactFiberUnwindWork.old.js
      • ReactInternalTypes.js
      • clz32.js
    • react-server/src
      • ReactFizzHooks.js
      • ReactFizzServer.js
      • ReactFizzTreeContext.js
      • ReactFlightServer.js
    • react-suspense-test-utils/src
      • ReactSuspenseTestUtils.js
    • react
      • index.classic.fb.js
      • index.experimental.js
      • index.js
      • index.modern.fb.js
      • index.stable.js
      • src
        • React.js
        • ReactHooks.js
      • unstable-shared-subset.experimental.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-debug-tools/src/ReactDebugHooks.js‎

Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/ReactDebugHooks.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
341341
return value;
342342
}
343343

344+
function useId(): string {
345+
const hook = nextHook();
346+
const id = hook !== null ? hook.memoizedState : '';
347+
hookLog.push({
348+
primitive: 'Id',
349+
stackError: new Error(),
350+
value: id,
351+
});
352+
return id;
353+
}
354+
344355
const Dispatcher: DispatcherType = {
345356
getCacheForType,
346357
readContext,
@@ -361,6 +372,7 @@ const Dispatcher: DispatcherType = {
361372
useSyncExternalStore,
362373
useDeferredValue,
363374
useOpaqueIdentifier,
375+
useId,
364376
};
365377

366378
// Inspect
Collapse file

‎packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js‎

Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js
+28-1Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ describe('ReactHooksInspectionIntegration', () => {
628628
it('should support composite useOpaqueIdentifier hook in concurrent mode', () => {
629629
function Foo(props) {
630630
const id = React.unstable_useOpaqueIdentifier();
631-
const [state] = React.useState(() => 'hello', []);
631+
const [state] = React.useState('hello');
632632
return <div id={id}>{state}</div>;
633633
}
634634

@@ -656,6 +656,33 @@ describe('ReactHooksInspectionIntegration', () => {
656656
});
657657
});
658658

659+
it('should support useId hook', () => {
660+
function Foo(props) {
661+
const id = React.unstable_useId();
662+
const [state] = React.useState('hello');
663+
return <div id={id}>{state}</div>;
664+
}
665+
666+
const renderer = ReactTestRenderer.create(<Foo />);
667+
const childFiber = renderer.root.findByType(Foo)._currentFiber();
668+
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
669+
670+
expect(tree.length).toEqual(2);
671+
672+
expect(tree[0].id).toEqual(0);
673+
expect(tree[0].isStateEditable).toEqual(false);
674+
expect(tree[0].name).toEqual('Id');
675+
expect(String(tree[0].value).startsWith('r:')).toBe(true);
676+
677+
expect(tree[1]).toEqual({
678+
id: 1,
679+
isStateEditable: true,
680+
name: 'State',
681+
value: 'hello',
682+
subHooks: [],
683+
});
684+
});
685+
659686
describe('useDebugValue', () => {
660687
it('should support inspectable values for multiple custom hooks', () => {
661688
function useLabeledValue(label) {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.