Skip to content

Allowing lifecycle metadata on inner component fns #47

@ptaoussanis

Description

@ptaoussanis

Hi Dan, hope you're well!

Think this might be clearer to explain with an example. It's currently possible to write something like:

(with-meta
  (fn outer-component [arg1 arg2]
    (let [local-state (atom {})] ; Perform setup, etc.
      (fn inner-component [arg1 arg2]
        [:div (str arg1 "," arg2 "," @local-state)])))
  {:component-did-mount (fn [this])})

This works, but the :component-did-mount fn has to do w/o access to local-state.

It's be nice to support something like this:

(fn outer-component [arg1 arg2]
  (let [local-state (atom {})] ; Perform setup, etc.
    (with-meta
      (fn inner-component [arg1 arg2]
        [:div (str arg1 "," arg2 "," @local-state)])
      {:component-did-mount
       (fn [this]
         ;; Has access to local-state (but doesn't currently trigger)
         )})))

I.e. by allowing lifecycle metadata on the inner component, we gain the ability to share local setup state with the mount fn.

Does that make sense?
Think it'd be feasible?
Any downsides?
Would a PR be welcome?

Thanks a lot! No urgency on this at all, know you've been busy.

Cheers :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions