You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8864126
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react/createElement.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ function Greeting({ name }) {
40
40
41
41
*`type`: The `type` argument must be a valid React component type. For example, it could be a tag name string (such as `'div'` or `'span'`), or a React component (a function, a class, or a special component like [`Fragment`](/reference/react/Fragment)).
42
42
43
-
*`props`: The `props` argument must either be an object or `null`. If you pass `null`, it will be treated the same as an empty object. React will create an element with props matching the `props` you have passed. Note that `ref` and `key`from your `props` object are special and will *not* be available as `element.props.ref` and `element.props.key` on the returned `element`. They will be available as `element.ref`and`element.key`.
43
+
*`props`: The `props` argument must either be an object or `null`. If you pass `null`, it will be treated the same as an empty object. React will create an element with props matching the `props` you have passed. React stores `key`separately on the returned element as `element.key`. In React 19, you can read a supplied `ref`as`element.props.ref`.
44
44
45
45
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
46
46
@@ -49,14 +49,15 @@ function Greeting({ name }) {
49
49
`createElement` returns a React element object with a few properties:
50
50
51
51
*`type`: The `type` you have passed.
52
-
*`props`: The `props` you have passed except for `ref` and `key`.
53
-
*`ref`: The `ref` you have passed. If missing, `null`.
52
+
*`props`: The props you passed, including `ref` if supplied. React reserves `key`.
54
53
*`key`: The `key` you have passed, coerced to a string. If missing, `null`.
55
54
56
55
Usually, you'll return the element from your component or make it a child of another element. Although you may read the element's properties, it's best to treat every element as opaque after it's created, and only render it.
57
56
58
57
#### Caveats {/*caveats*/}
59
58
59
+
* In React 19, `element.ref` is deprecated. Read `element.props.ref` when you need the ref on an existing element.
60
+
60
61
* You must **treat React elements and their props as [immutable](https://en.wikipedia.org/wiki/Immutable_object)** and never change their contents after creation. In development, React will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) the returned element and its `props` property shallowly to enforce this.
61
62
62
63
* When you use JSX, **you must start a tag with a capital letter to render your own custom component.** In other words, `<Something />` is equivalent to `createElement(Something)`, but `<something />` (lowercase) is equivalent to `createElement('something')` (note it's a string, so it will be treated as a built-in HTML tag).
0 commit comments