MCPcopy
hub / github.com/preactjs/preact / createSuspender

Function createSuspender

compat/test/browser/suspense-utils.js:88–116  ·  view source on GitHub ↗
(DefaultComponent)

Source from the content-addressed store, hash-verified

86 * @returns {[typeof Suspender, () => Resolvers]}
87 */
88export function createSuspender(DefaultComponent) {
89 /** @type {(lazy: typeof Component) => void} */
90 let renderLazy;
91 class Suspender extends Component {
92 constructor(props, context) {
93 super(props, context);
94 this.state = { Lazy: null };
95
96 renderLazy = Lazy => this.setState({ Lazy });
97 }
98
99 render(props, state) {
100 return state.Lazy ? h(state.Lazy, props) : h(DefaultComponent, props);
101 }
102 }
103
104 sinon.spy(Suspender.prototype, 'render');
105
106 /**
107 * @returns {Resolvers}
108 */
109 function suspend() {
110 const [Lazy, resolve, reject] = createLazy();
111 renderLazy(Lazy);
112 return [resolve, reject];
113 }
114
115 return [Suspender, suspend];
116}
117
118/**
119 * @returns {[() => any, (data: any) => Promise<any>, (error: Error) => Promise<any>]}

Callers 1

suspense.test.jsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…