diff --git a/src/content/warnings/unknown-prop.md b/src/content/warnings/unknown-prop.md index 80bcdb14296..f82043381c8 100644 --- a/src/content/warnings/unknown-prop.md +++ b/src/content/warnings/unknown-prop.md @@ -1,61 +1,1447 @@ ---- -title: Unknown Prop Warning ---- - -The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as a legal DOM attribute/property. You should ensure that your DOM elements do not have spurious props floating around. - -There are a couple of likely reasons this warning could be appearing: - -1. Are you using `{...props}` or `cloneElement(element, props)`? When copying props to a child component, you should ensure that you are not accidentally forwarding props that were intended only for the parent component. See common fixes for this problem below. - -2. You are using a non-standard DOM attribute on a native DOM node, perhaps to represent custom data. If you are trying to attach custom data to a standard DOM element, consider using a custom data attribute as described [on MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes). - -3. React does not yet recognize the attribute you specified. This will likely be fixed in a future version of React. React will allow you to pass it without a warning if you write the attribute name lowercase. - -4. You are using a React component without an upper case, for example ``. React interprets it as a DOM tag because React JSX transform uses the upper vs. lower case convention to distinguish between user-defined components and DOM tags. For your own React components, use PascalCase. For example, write `` instead of ``. - ---- - -If you get this warning because you pass props like `{...props}`, your parent component needs to "consume" any prop that is intended for the parent component and not intended for the child component. Example: - -**Bad:** Unexpected `layout` prop is forwarded to the `div` tag. - -```js -function MyDiv(props) { - if (props.layout === 'horizontal') { - // BAD! Because you know for sure "layout" is not a prop that
understands. - return
- } else { - // BAD! Because you know for sure "layout" is not a prop that
understands. - return
- } -} -``` - -**Good:** The spread syntax can be used to pull variables off props, and put the remaining props into a variable. - -```js -function MyDiv(props) { - const { layout, ...rest } = props - if (layout === 'horizontal') { - return
- } else { - return
- } -} -``` - -**Good:** You can also assign the props to a new object and delete the keys that you're using from the new object. Be sure not to delete the props from the original `this.props` object, since that object should be considered immutable. - -```js -function MyDiv(props) { - const divProps = Object.assign({}, props); - delete divProps.layout; - - if (props.layout === 'horizontal') { - return
- } else { - return
- } -} -``` +--- +title: Unknown Prop Warning +--- + +The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as a legal DOM attribute/property. You should ensure that your DOM elements do not have spurious props floating around. + +There are a couple of likely reasons this warning could be appearing: + +1. Are you using `{...props}` or `cloneElement(element, props)`? When copying props to a child component, you should ensure that you are not accidentally forwarding props that were intended only for the parent component. See common fixes for this problem below. + +2. You are using a non-standard DOM attribute on a native DOM node, perhaps to represent custom data. If you are trying to attach custom data to a standard DOM element, consider using a custom data attribute as described [on MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes). + +3. React does not yet recognize the attribute you specified. This will likely be fixed in a future version of React. React will allow you to pass it without a warning if you write the attribute name lowercase. + +4. You are using a React component without an upper case, for example ``. React interprets it as a DOM tag because React JSX transform uses the upper vs. lower case convention to distinguish between user-defined components and DOM tags. For your own React components, use PascalCase. For example, write `` instead of ``.4. You are using a React component without an upper case, for example ``. React interprets it as a DOM tag because React JSX transform uses the upper vs. lower case convention to distinguish between user-defined components and DOM tags. For your own React components, use PascalCase. For example, write `` instead of ``. + +### Valid Elements in Select Tags + +When using ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid ` +``` + +This matches the HTML specification for valid `