lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
624 stars 52 forks source link

docs/pro-tips: Update defnc macro example for modern usages #132

Closed rome-user closed 1 year ago

rome-user commented 1 year ago

The old custom macro does not support fn-meta. Attempts to use fn-meta with the old version will result in errors, since the custom macro will not insert code properly into helix.core/defnc.

To quickly test this, try something as simple as this:

;;; Make sure you are using your own custom `defnc` macro!

(defnc FancyButton
  "Example lifted straight from React documentation."
  {:wrap [(react/forwardRef)]}
  [{:keys [children]} ref]
  (d/button {:ref ref :class "FancyButton"} children))

(defnc Parent []
  (let [ref (hooks/use-ref nil)]
    ($ FancyButton {:ref ref} "Click me!")))

You will get compile error when using the old custom macro, but not the updated one I provide in this PR.

lilactown commented 1 year ago

❤️