MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / validateChildKeys

Function validateChildKeys

code/higher-order-components/public/app.js:19492–19524  ·  view source on GitHub ↗

* Ensure that every element either is passed in a static location, in an * array with an explicit keys property defined, or in an object literal * with valid key property. * * @internal * @param {ReactNode} node Statically passed child of any type. * @param {*} parentType node's parent's type.

(node, parentType)

Source from the content-addressed store, hash-verified

19490 * @param {*} parentType node's parent's type.
19491 */
19492function validateChildKeys(node, parentType) {
19493 if (typeof node !== 'object') {
19494 return;
19495 }
19496 if (Array.isArray(node)) {
19497 for (var i = 0; i < node.length; i++) {
19498 var child = node[i];
19499 if (isValidElement(child)) {
19500 validateExplicitKey(child, parentType);
19501 }
19502 }
19503 } else if (isValidElement(node)) {
19504 // This element was passed in a valid location.
19505 if (node._store) {
19506 node._store.validated = true;
19507 }
19508 } else if (node) {
19509 var iteratorFn = getIteratorFn(node);
19510 if (typeof iteratorFn === 'function') {
19511 // Entry iterators used to provide implicit keys,
19512 // but now we print a separate warning for them later.
19513 if (iteratorFn !== node.entries) {
19514 var iterator = iteratorFn.call(node);
19515 var step = void 0;
19516 while (!(step = iterator.next()).done) {
19517 if (isValidElement(step.value)) {
19518 validateExplicitKey(step.value, parentType);
19519 }
19520 }
19521 }
19522 }
19523 }
19524}
19525
19526/**
19527 * Given an element, validate that its props follow the propTypes definition,

Callers 2

Calls 3

isValidElementFunction · 0.70
validateExplicitKeyFunction · 0.70
getIteratorFnFunction · 0.70

Tested by

no test coverage detected