From 819f945e7eb8834b5833b611008d4c64016012ea Mon Sep 17 00:00:00 2001 From: Jim Higson Date: Mon, 27 Jan 2025 09:38:24 +0000 Subject: [PATCH] Update cloneElement.md to match types in @types/react --- src/content/reference/react/cloneElement.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/reference/react/cloneElement.md b/src/content/reference/react/cloneElement.md index 6bcea51b057..af72b8f3f54 100644 --- a/src/content/reference/react/cloneElement.md +++ b/src/content/reference/react/cloneElement.md @@ -49,7 +49,7 @@ console.log(clonedElement); // Goodbye * `element`: The `element` argument must be a valid React element. For example, it could be a JSX node like ``, the result of calling [`createElement`](/reference/react/createElement), or the result of another `cloneElement` call. -* `props`: The `props` argument must either be an object or `null`. If you pass `null`, the cloned element will retain all of the original `element.props`. Otherwise, for every prop in the `props` object, the returned element will "prefer" the value from `props` over the value from `element.props`. The rest of the props will be filled from the original `element.props`. If you pass `props.key` or `props.ref`, they will replace the original ones. +* `props`: The `props` argument must either be an object or `undefined`. If you pass `undefined`, the cloned element will retain all of the original `element.props`. Otherwise, for every prop in the `props` object, the returned element will "prefer" the value from `props` over the value from `element.props`. The rest of the props will be filled from the original `element.props`. If you pass `props.key` or `props.ref`, they will replace the original ones. * **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. If you don't pass any `...children` arguments, the original `element.props.children` will be preserved. @@ -68,7 +68,7 @@ Usually, you'll return the element from your component or make it a child of ano * Cloning an element **does not modify the original element.** -* You should only **pass children as multiple arguments to `cloneElement` if they are all statically known,** like `cloneElement(element, null, child1, child2, child3)`. If your children are dynamic, pass the entire array as the third argument: `cloneElement(element, null, listItems)`. This ensures that React will [warn you about missing `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key) for any dynamic lists. For static lists this is not necessary because they never reorder. +* You should only **pass children as multiple arguments to `cloneElement` if they are all statically known,** like `cloneElement(element, undefined, child1, child2, child3)`. If your children are dynamic, pass the entire array as the third argument: `cloneElement(element, undefined, listItems)`. This ensures that React will [warn you about missing `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key) for any dynamic lists. For static lists this is not necessary because they never reorder. * `cloneElement` makes it harder to trace the data flow, so **try the [alternatives](#alternatives) instead.**