Make assert stable ref error more explicit

Reviewed By: ivanmisuno

Differential Revision: D46359534

fbshipit-source-id: 002e4e8ae9168cf2cf3b652fc853416de825861f
This commit is contained in:
Andrey Goncharov
2023-06-06 03:44:48 -07:00
committed by Facebook GitHub Bot
parent 2f2754f56a
commit b9322247e6
2 changed files with 2 additions and 2 deletions

View File

@@ -102,6 +102,6 @@ test('it does not allow changing key', async () => {
console.error = orig; console.error = orig;
} }
}).toThrowErrorMatchingInlineSnapshot( }).toThrowErrorMatchingInlineSnapshot(
`"[useAssertStableRef] An unstable reference was passed to this component as property 'key'. For optimization purposes we expect that this prop doesn't change over time. You might want to create the value passed to this prop outside the render closure, store it in useCallback / useMemo / useState, or set a key on the parent component"`, `"[useAssertStableRef] An unstable reference was passed to this component as property 'key'. For optimization purposes we expect that this prop doesn't change over time. You might want to create the value passed to this prop outside the render closure, store it in useCallback / useMemo / useState, or set a key on the parent component. Prev value: x. New value: y"`,
); );
}); });

View File

@@ -20,7 +20,7 @@ export const useAssertStableRef = !isProduction()
const ref = useRef(value); const ref = useRef(value);
if (ref.current !== value) { if (ref.current !== value) {
throw new Error( throw new Error(
`[useAssertStableRef] An unstable reference was passed to this component as property '${prop}'. For optimization purposes we expect that this prop doesn't change over time. You might want to create the value passed to this prop outside the render closure, store it in useCallback / useMemo / useState, or set a key on the parent component`, `[useAssertStableRef] An unstable reference was passed to this component as property '${prop}'. For optimization purposes we expect that this prop doesn't change over time. You might want to create the value passed to this prop outside the render closure, store it in useCallback / useMemo / useState, or set a key on the parent component. Prev value: ${ref.current}. New value: ${value}`,
); );
} }
} }