MCPcopy
hub / github.com/react/react / jsxProd

Function jsxProd

packages/react/src/jsx/ReactJSXElement.js:282–331  ·  view source on GitHub ↗
(type, config, maybeKey)

Source from the content-addressed store, hash-verified

280 * @param {string} key
281 */
282export function jsxProd(type, config, maybeKey) {
283 let key = null;
284
285 // Currently, key can be spread in as a prop. This causes a potential
286 // issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
287 // or <div key="Hi" {...props} /> ). We want to deprecate key spread,
288 // but as an intermediary step, we will use jsxDEV for everything except
289 // <div {...props} key="Hi" />, because we aren't currently able to tell if
290 // key is explicitly declared to be undefined or not.
291 if (maybeKey !== undefined) {
292 if (__DEV__) {
293 checkKeyStringCoercion(maybeKey);
294 }
295 key = '' + maybeKey;
296 }
297
298 if (hasValidKey(config)) {
299 if (__DEV__) {
300 checkKeyStringCoercion(config.key);
301 }
302 key = '' + config.key;
303 }
304
305 let props;
306 if (!('key' in config)) {
307 // If key was not spread in, we can reuse the original props object. This
308 // only works for `jsx`, not `createElement`, because `jsx` is a compiler
309 // target and the compiler always passes a new object. For `createElement`,
310 // we can't assume a new object is passed every time because it can be
311 // called manually.
312 //
313 // Spreading key is a warning in dev. In a future release, we will not
314 // remove a spread key from the props object. (But we'll still warn.) We'll
315 // always pass the object straight through.
316 props = config;
317 } else {
318 // We need to remove reserved props (key, prop, ref). Create a fresh props
319 // object and copy over all the non-reserved props. We don't use `delete`
320 // because in V8 it will deopt the object to dictionary mode.
321 props = {};
322 for (const propName in config) {
323 // Skip over reserved prop names
324 if (propName !== 'key') {
325 props[propName] = config[propName];
326 }
327 }
328 }
329
330 return ReactElement(type, key, props, getOwner(), undefined, undefined);
331}
332
333// While `jsxDEV` should never be called when running in production, we do
334// support `jsx` and `jsxs` when running in development. This supports the case

Callers

nothing calls this directly

Calls 4

checkKeyStringCoercionFunction · 0.90
hasValidKeyFunction · 0.70
ReactElementFunction · 0.70
getOwnerFunction · 0.70

Tested by

no test coverage detected