Skip to content

Commit a8fc03d

Browse files
committed
Component-and-props: add invalid prop name docs
1 parent 9e6e19e commit a8fc03d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pages/docs/react/latest/components-and-props.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ You can't define any props called `key` or `ref`. React treats those props diffe
149149

150150
Check out the corresponding [Arrays and Keys](./arrays-and-keys) and [Forwarding React Refs](./forwarding-refs) sections for more details.
151151

152+
### Handling Invalid Prop Names (e.g. keywords)
153+
154+
Prop names like `type` (as in `<input type="text" />`) aren't syntactically valid; `type` is a reserved keyword in ReScript. Use `<input type_="text" />` instead.
155+
156+
For `aria-*` use camelCasing, e.g., `ariaLabel`. For DOM components, we'll translate it to `aria-label` under the hood.
157+
158+
For `data-*` this is a bit trickier; words with `-` in them aren't valid in ReScript. When you do want to write them, e.g., `<div data-name="click me" />`, check out the [React.cloneElement](./rendering-elements#cloning-elements) or [React.createDOMElementVariadic](./rendering-elements#creating-dom-elements) section.
159+
160+
152161
## Children Props
153162

154163
In React `props.children` is a special attribute to represent the nested elements within a parent element:

0 commit comments

Comments
 (0)