MCPcopy Create free account
hub / github.com/reactjs/react-rails / renderWithHooks

Function renderWithHooks

lib/assets/react-source/development/react.js:18459–18568  ·  view source on GitHub ↗
(current, workInProgress, Component, props, secondArg, nextRenderExpirationTime)

Source from the content-addressed store, hash-verified

18457 }
18458
18459 function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderExpirationTime) {
18460 renderExpirationTime = nextRenderExpirationTime;
18461 currentlyRenderingFiber$1 = workInProgress;
18462
18463 {
18464 hookTypesDev = current !== null ? current._debugHookTypes : null;
18465 hookTypesUpdateIndexDev = -1; // Used for hot reloading:
18466
18467 ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
18468 }
18469
18470 workInProgress.memoizedState = null;
18471 workInProgress.updateQueue = null;
18472 workInProgress.expirationTime = NoWork; // The following should have already been reset
18473 // currentHook = null;
18474 // workInProgressHook = null;
18475 // didScheduleRenderPhaseUpdate = false;
18476 // TODO Warn if no hooks are used at all during mount, then some are used during update.
18477 // Currently we will identify the update render as a mount because memoizedState === null.
18478 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
18479 // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
18480 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
18481 // so memoizedState would be null during updates and mounts.
18482
18483 {
18484 if (current !== null && current.memoizedState !== null) {
18485 ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
18486 } else if (hookTypesDev !== null) {
18487 // This dispatcher handles an edge case where a component is updating,
18488 // but no stateful hooks have been used.
18489 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
18490 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
18491 // This dispatcher does that.
18492 ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
18493 } else {
18494 ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
18495 }
18496 }
18497
18498 var children = Component(props, secondArg); // Check if there was a render phase update
18499
18500 if (workInProgress.expirationTime === renderExpirationTime) {
18501 // Keep rendering in a loop for as long as render phase updates continue to
18502 // be scheduled. Use a counter to prevent infinite loops.
18503 var numberOfReRenders = 0;
18504
18505 do {
18506 workInProgress.expirationTime = NoWork;
18507
18508 if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
18509 {
18510 throw Error( "Too many re-renders. React limits the number of renders to prevent an infinite loop." );
18511 }
18512 }
18513
18514 numberOfReRenders += 1;
18515
18516 {

Callers 3

updateForwardRefFunction · 0.85
updateFunctionComponentFunction · 0.85

Calls 1

ComponentFunction · 0.70

Tested by

no test coverage detected