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

Shortcut to call create-element and create functional components #494

Closed
Deraen opened this issue Apr 26, 2020 · 4 comments
Closed

Shortcut to call create-element and create functional components #494

Deraen opened this issue Apr 26, 2020 · 4 comments

Comments

@Deraen
Copy link
Member

Deraen commented Apr 26, 2020

Currently Reagent has one shortcut to control how components are created:

  • :> as shortcut to adapt-react-class which in effect calls create-element and converts the Cljs properties to JS object (doesn't wrap the component in Reagent implementation, so Ratoms won't work inside these components)
  • :<> isn't really shortcut, but just special element

I want to add two more:

  • Shortcut to call create-element without properties conversion, so Cljs values can be passed to the component as is, without Reagent wrapping the component.
    • Maybe: [:$ react-component #js {:foo "bar" :cljs-vector [1 2 3]}]
  • Shortcut to create functional component, same as with the new (r/create-compiler {:functional-components? true}) but without changing the compiler.
    • Not sure what would be good character for this one.
  • Wrapping all the function component in Reagent ratom wrapper (the second case) could work for React components also, but is unncessary?
    • These are also wrapped in React/memo as Reagent components are pure, but that might not be the case for React functions?
@Deraen
Copy link
Member Author

Deraen commented Apr 26, 2020

Maybe:

  • :>> for "raw" create-element call
  • :$ for Reagent function component

@minikomi
Copy link

minikomi commented Apr 27, 2020

Just spitballing - how about keeping the :> class for component generation, but with a tag, eg.

  • :r> for "raw" prop passing
  • :f> for functional..

Then, it can be easily extended in the future and :<> is just a subset of that class too.

@Deraen
Copy link
Member Author

Deraen commented Apr 27, 2020

Nice. We could also deprecate :> (keeps working but prints one deprecation notice) and create named version for that (maybe :a> for "adapt"), or even decide one that automatically converts the props isn't that useful.

@Deraen
Copy link
Member Author

Deraen commented May 1, 2020

:r> and :f> added to master.

:r> keeps the props as is, but converts the Hiccup children to React elements. Note that props should be JS object ~always (I think) because React crateElement doesn't work otherwise, and React will also add children property to the JS object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants