Skip to content

Commit f0befae

Browse files
authored
Tweak context invariant message (#14671)
1 parent a129259 commit f0befae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: packages/react-reconciler/src/ReactFiberNewContext.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,10 @@ export function readContext<T>(
330330
if (lastContextDependency === null) {
331331
invariant(
332332
currentlyRenderingFiber !== null,
333-
'Context can only be read while React is ' +
334-
'rendering, e.g. inside the render method or getDerivedStateFromProps.',
333+
'Context can only be read while React is rendering. ' +
334+
'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
335+
'In function components, you can read it directly in the function body, but not ' +
336+
'inside Hooks like useReducer() or useMemo().',
335337
);
336338

337339
// This is the first dependency for this component. Create a new list.

0 commit comments

Comments
 (0)