Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] React.cloneElement #3363

Merged
merged 1 commit into from
Mar 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/docs/ref-01-top-level-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ Create and return a new `ReactElement` of the given type. The type argument can
html tag name string (eg. 'div', 'span', etc), or a `ReactClass` (created via `React.createClass`).


### React.cloneElement

```
ReactElement cloneElement(
ReactElement element,
[object props],
[children ...]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are missing a type on children

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have a type, it's var args and can be an array, an element, a string, a number, a bool... which basically maps to ReactNode but that's not really a super well defined type, so meh. We already have it exactly like this for createElement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's a varargs, it shouldn't be inside array brackets, should it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its optional.

anyway, let's fix all of these as a whole. if you really want to do it now, do it and make sure it happens in all our API docs. But we won't change just this one - this fits with the rest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, I prefer incremental correctness over consistency, but sure. Looks good to me.

)
```

Clone and return a new `ReactElement` using `element` as the starting point. The resulting element will have the original element's props with the new props merged in shallowly. New children will replace existing children. Unlike `React.addons.cloneWithProps`, `key` and `ref` from the original element will be preserved. There is no special behavior for merging any props (unlike `cloneWithProps`). See the [v0.13 RC2 blog post](/react/blog/2015/03/03/react-v0.13-rc2.html) for additional details.


### React.createFactory

```javascript
Expand Down