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

Function pushProvider

packages/react-server/src/ReactFizzNewContext.js:180–228  ·  view source on GitHub ↗
(
  context: ReactContext<T>,
  nextValue: T,
)

Source from the content-addressed store, hash-verified

178}
179
180export function pushProvider<T>(
181 context: ReactContext<T>,
182 nextValue: T,
183): ContextSnapshot {
184 let prevValue;
185 if (isPrimaryRenderer) {
186 prevValue = context._currentValue;
187 context._currentValue = nextValue;
188 if (__DEV__) {
189 if (
190 context._currentRenderer !== undefined &&
191 context._currentRenderer !== null &&
192 context._currentRenderer !== rendererSigil
193 ) {
194 console.error(
195 'Detected multiple renderers concurrently rendering the ' +
196 'same context provider. This is currently unsupported.',
197 );
198 }
199 context._currentRenderer = rendererSigil;
200 }
201 } else {
202 prevValue = context._currentValue2;
203 context._currentValue2 = nextValue;
204 if (__DEV__) {
205 if (
206 context._currentRenderer2 !== undefined &&
207 context._currentRenderer2 !== null &&
208 context._currentRenderer2 !== rendererSigil
209 ) {
210 console.error(
211 'Detected multiple renderers concurrently rendering the ' +
212 'same context provider. This is currently unsupported.',
213 );
214 }
215 context._currentRenderer2 = rendererSigil;
216 }
217 }
218 const prevNode = currentActiveSnapshot;
219 const newNode: ContextNode<T> = {
220 parent: prevNode,
221 depth: prevNode === null ? 0 : prevNode.depth + 1,
222 context: context,
223 parentValue: prevValue,
224 value: nextValue,
225 };
226 currentActiveSnapshot = newNode;
227 return newNode;
228}
229
230export function popProvider<T>(context: ReactContext<T>): ContextSnapshot {
231 const prevSnapshot = currentActiveSnapshot;

Callers 1

renderContextProviderFunction · 0.90

Calls 1

errorMethod · 0.65

Tested by

no test coverage detected