Docs / ReasonReact / CloneElement

Clone Element

The Record API is in feature-freeze. For the newest features and better support going forward, please consider migrating to the new function components.

Signature: let cloneElement: (reactElement, ~props: Js.t({..})=?, 'anyChildrenType) => reactElement

Same as ReactJS' cloneElement. However, adding extra props to a ReasonReact component doesn't make sense; you'd use a render prop. Therefore, ReasonReact.cloneElement is only used in edge-cases to convert over existing code.

let clonedElement = ReasonReact.cloneElement( <div className="foo" />, ~props={"payload": 1}, [||] );

The props value is unsafe, be careful!

You can also use cloneElement to simulate prop spreading, but this is discouraged in ReasonReact.