MCPcopy
hub / github.com/facebook/react / lazy

Function lazy

packages/react/src/ReactLazy.js:195–232  ·  packages/react/src/ReactLazy.js::lazy
(
  ctor: () => Thenable<{default: T, ...}>,
)

Source from the content-addressed store, hash-verified

193}
194
195export function lazy<T>(
196 ctor: () => Thenable<{default: T, ...}>,
197): LazyComponent<T, Payload<T>> {
198 const payload: Payload<T> = {
199 class="cm">// We use these fields to store the result.
200 _status: Uninitialized,
201 _result: ctor,
202 };
203
204 const lazyType: LazyComponent<T, Payload<T>> = {
205 $$typeof: REACT_LAZY_TYPE,
206 _payload: payload,
207 _init: lazyInitializer,
208 };
209
210 if (__DEV__ && enableAsyncDebugInfo) {
211 class="cm">// TODO: We should really track the owner here but currently ReactIOInfo
212 class="cm">// can only contain ReactComponentInfo and not a Fiber. It's unusual to
213 class="cm">// create a lazy inside an owner though since they should be in module scope.
214 const owner = null;
215 const ioInfo: ReactIOInfo = {
216 name: class="st">'lazy',
217 start: -1,
218 end: -1,
219 value: null,
220 owner: owner,
221 debugStack: new Error(class="st">'react-stack-top-frame'),
222 class="cm">// eslint-disable-next-line react-internal/no-production-logging
223 debugTask: console.createTask ? console.createTask(class="st">'lazy()') : null,
224 };
225 payload._ioInfo = ioInfo;
226 class="cm">// Add debug info to the lazy, but this doesn't have an await stack yet.
227 class="cm">// That will be inferred by later usage.
228 lazyType._debugInfo = [{awaited: ioInfo}];
229 }
230
231 return lazyType;
232}

Callers 4

index.jsFile · 0.90
App.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected