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

Function validateChildKeys

code/event-handlers/public/app.js:18828–18860  ·  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

18826 * @param {*} parentType node's parent's type.
18827 */
18828function validateChildKeys(node, parentType) {
18829 if (typeof node !== 'object') {
18830 return;
18831 }
18832 if (Array.isArray(node)) {
18833 for (var i = 0; i < node.length; i++) {
18834 var child = node[i];
18835 if (isValidElement(child)) {
18836 validateExplicitKey(child, parentType);
18837 }
18838 }
18839 } else if (isValidElement(node)) {
18840 // This element was passed in a valid location.
18841 if (node._store) {
18842 node._store.validated = true;
18843 }
18844 } else if (node) {
18845 var iteratorFn = getIteratorFn(node);
18846 if (typeof iteratorFn === 'function') {
18847 // Entry iterators used to provide implicit keys,
18848 // but now we print a separate warning for them later.
18849 if (iteratorFn !== node.entries) {
18850 var iterator = iteratorFn.call(node);
18851 var step = void 0;
18852 while (!(step = iterator.next()).done) {
18853 if (isValidElement(step.value)) {
18854 validateExplicitKey(step.value, parentType);
18855 }
18856 }
18857 }
18858 }
18859 }
18860}
18861
18862/**
18863 * 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