Skip to content

with-key and with-ref Removing children? #252

@zonotope

Description

@zonotope

The rum.core/with-key and rum.core/with-ref functions call the underlying React .cloneElement function to create a new React component that includes the supplied key or ref, respectively. Both with-key and with-ref use full function signature version of .cloneElement and pass nil for the optional last argument corresponding to the new component's children. This leads to the resulting component missing the children of the original. If the smaller arity function signature is used omitting the nil, the resulting component will have all of the original component's children.

Is this intended? If so, what is the proper way to use with-key and with-ref so the resulting components also includes the original component's children?

If this was not intended, I have defined these functions as a workaround that works for me:

(defn with-key
  [elt k]
  (js/React.cloneElement elt #js {"key" k}))

(defn with-ref
  [elt r]
  (js/React.cloneElement elt #js {"ref" r}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions