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

Helper for HoC #9

Closed
lilactown opened this issue Nov 18, 2018 · 2 comments
Closed

Helper for HoC #9

lilactown opened this issue Nov 18, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@lilactown
Copy link
Collaborator

lilactown commented Nov 18, 2018

Right now, creating components that need to be wrapped in HOC (especially multiple HOC) is a bit cumbersome.

See https://github.com/Lokeh/hx/blob/master/examples/workshop/sortable.cljs and https://github.com/Lokeh/hx/blob/master/examples/workshop/react_dnd.cljs for examples.

I could imagine an API similar to:

(hx/defnc DraggableBox [{:keys [connect-drag-source top left text] :as props}]
  ;; key `:wrap` defines a vector of HoCs to wrap the component in
  {:hx/wrap [(dnd/DragSource "box"
                       box-spec
                       ;; this maps the react-dnd context to props for our
                       ;; component
                       (fn [connect]
                         #js {:connectDragSource (. connect dragSource)}))]}
  ;; render body
  (connect-drag-source
   (hx/f [:div {:style {:top top
                        :left left
                        :position "absolute"
                        :border "1px solid #333"}}
          text])))

The defnc macro could define two vars in the call site: DraggableBox which is the wrapped component, and DraggableBox_Render which is the non-wrapped component as written in the body of the defnc macro.

With the Hooks proposal gaining such momentum and mindshare, this might eventually be an unneeded enhancement. In the meantime, many React libraries are implemented as a collection of HoCs, so it might be smart to introduce this and then deprecate it once Hooks has been released in a stable version of React.

@lilactown lilactown added enhancement New feature or request good first issue Good for newcomers labels Nov 18, 2018
@lilactown lilactown removed the good first issue Good for newcomers label Dec 25, 2018
@pepe
Copy link

pepe commented Feb 11, 2019

Just for the history record, react-spring removed all the references to HoC style and went hooks only on the home page. I think it is telling.

@lilactown
Copy link
Collaborator Author

Implemented in master

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

2 participants