reason-react/docs/clone-element.md at main · feihong/reason-react · GitHub
Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 1020 Bytes

File metadata and controls

24 lines (18 loc) · 1020 Bytes
title cloneElement
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.