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

Spread props should work with a raw JS obj #41

Closed
lilactown opened this issue Apr 10, 2020 · 1 comment
Closed

Spread props should work with a raw JS obj #41

lilactown opened this issue Apr 10, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@lilactown
Copy link
Owner

Sometimes you get a JS object and want to forward it as props to a component.

What we'd like to do:

(defnc my-component []
  ;; `some-lib/Foo` is an external lib that uses a common pattern:
  ;; pass it a function-as-children which it then passes props to as a JS object
  ($ some-lib/Foo
   (fn [foo-props]
     (d/div {& foo-props} "I'm so foo-y!"))))

Currently, this requires converting or wrapping foo-props so that it is a CLJS map-alike, so that spread props works.

(defnc my-component []
  ($ some-lib/Foo
   (fn [foo-props]
     ;; wrap it in a bean, so that it can then be converted into a JS obj again... :sad:
     (d/div {& (cljs-bean.core/bean foo-props)} "I'm so foo-y!"))))

To support writing spread props like in the first snippet, spread props should check to see if it's a map-alike and if not, fall back to merging it in by Object.keys.

@lilactown lilactown added the enhancement New feature or request label Apr 28, 2020
@lilactown
Copy link
Owner Author

Fixed with #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant