(context: ReactContext<T>)
| 500 | } |
| 501 | |
| 502 | export function readContext<T>(context: ReactContext<T>): T { |
| 503 | if (__DEV__) { |
| 504 | // This warning would fire if you read context inside a Hook like useMemo. |
| 505 | // Unlike the class check below, it's not enforced in production for perf. |
| 506 | if (isDisallowedContextReadInDEV) { |
| 507 | console.error( |
| 508 | 'Context can only be read while React is rendering. ' + |
| 509 | 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + |
| 510 | 'In function components, you can read it directly in the function body, but not ' + |
| 511 | 'inside Hooks like useReducer() or useMemo().', |
| 512 | ); |
| 513 | } |
| 514 | } |
| 515 | return readContextForConsumer(currentlyRenderingFiber, context); |
| 516 | } |
| 517 | |
| 518 | export function readContextDuringReconciliation<T>( |
| 519 | consumer: Fiber, |
no test coverage detected