From f395afdd4aec262b4b5b9c1f0db4648dd34ca6b3 Mon Sep 17 00:00:00 2001 From: Raghunath Prabhakar <82239949+Raghuboi@users.noreply.github.com> Date: Fri, 15 Aug 2025 15:38:49 -0500 Subject: [PATCH] add regression test for custom hook named "useState" crash --- .../src/__tests__/inspectedElement-test.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js index 09f811172f30..3e664baa36b8 100644 --- a/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js +++ b/packages/react-devtools-shared/src/__tests__/inspectedElement-test.js @@ -2492,6 +2492,26 @@ describe('InspectedElement', () => { `); }); + it('should handle custom hooks named "useState" without crashing', async () => { + function useState() { + React.useState(0); + React.useEffect(() => () => {}); + } + + function Counter() { + useState(); + React.useState(0); + return null; + } + + await utils.actAsync(() => render()); + + const inspectedElement = await inspectElementAtIndex(0); + + expect(inspectedElement).not.toBe(null); + expect(Array.isArray(inspectedElement.hooks)).toBe(true); + }); + it('should support class components', async () => { class Example extends React.Component { state = {