Custom FieldTemplate and WrapIfAdditionalTemplate handle the keyNotAllowed prop
Detect
- Your custom
FieldTemplaterendersWrapIfAdditionalTemplateand lists the props it passes one by one. - Your custom
WrapIfAdditionalTemplatespreads the props it doesn't use onto a DOM element, and React warns in the console about an unknownkeyNotAllowedprop on that element.
Change
A custom FieldTemplate adds keyNotAllowed to the props it forwards, or the forbidden key isn't marked:
<WrapIfAdditionalTemplate
hasErrors={hasErrors}
keyName={keyName}
+ keyNotAllowed={keyNotAllowed}
{...otherForwardedProps}
>
The other props it forwards, hasErrors and keyName, are covered in Custom field, array and object templates take their error state from hasErrors.
A custom WrapIfAdditionalTemplate that spreads the rest of its props leaves keyNotAllowed out:
-const { children, label, ...rest } = props;
+const { children, label, keyNotAllowed, ...rest } = props;
return <div {...rest}>{children}</div>;
Verify
- A forbidden key's row shows
The key "%1" is not allowed here. - React logs no unknown-prop warning for
keyNotAllowed.
Also read: