> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Function: cloneElement()

> **cloneElement**\<`Props`>(`element`: `ReactElement`\<`Props`>, `props?`: `Partial`\<`Props`> & `Attributes` | `null`, ...`children`: `ReactNode`\[]): `ReactElement`\<`Props`>

Clones an element with optional replacement props and children.

## Type Parameters

| Type Parameter |
| -------------- |
| `Props`        |

## Parameters

| Parameter      | Type                                         |
| -------------- | -------------------------------------------- |
| `element`      | `ReactElement`\<`Props`>                     |
| `props?`       | `Partial`\<`Props`> & `Attributes` \| `null` |
| ...`children?` | `ReactNode`\[]                               |

## Returns

`ReactElement`\<`Props`>

## Example

**This is an example below: react-apis**

**Entry:** `src/clone-element`
**Bundle:** `dist/clone-element.lynx.bundle` | Web: `dist/clone-element.web.bundle`

```tsx
import { cloneElement, root, useState } from "@lynx-js/react";

import "./index.css";

const products = ["Cabbage", "Garlic", "Apple"];

const nativeRows = products.map((title) => (
  <view key={title}>
    <text className="RowText">{title}</text>
  </view>
));

function CloneElementExample() {
  const [selectedIndex, setSelectedIndex] = useState(0);

  const selectNext = () => {
    setSelectedIndex((current) => (current + 1) % nativeRows.length);
  };

  return (
    <view className="App">
      <view className="List">
        {nativeRows.map((row, index) =>
          cloneElement(row, {
            className: index === selectedIndex ? "Row RowHighlighted" : "Row",
          })
        )}
      </view>

      <view className="Button" bindtap={selectNext}>
        <text className="ButtonText">Next</text>
      </view>
    </view>
  );
}

root.render(<CloneElementExample />);

```

v0.2.0


