-
Notifications
You must be signed in to change notification settings - Fork 16
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
Experience Report #50
Comments
Thanks for the report. Very happy to hear a successful story. |
I appreciate the time you put into writing this up! I'm glad you're feeling productive in it and that it's solving a pain point for you with other libraries. A couple things that might help:
(def my-app-context (react/createContext))
(def ctx (reagent-context.core/->Context my-app-context))
(hx.react/defnc [props]
(let [ctx-value (react/useContext my-app-context)]
[:div (prn ctx-value)]))
(reagent-context.core/defconsumer my-component ctx
[ctx-value prop1 prop2]
[:div (prn ctx-value)])
Once again, thanks for taking the time to write this up and I hope that we can help aid in things like clearer documentation and easier interop with existing libraries. |
@tomconnors I would love some numbers about the code size. Did switching to hx reduce the final bundle size? |
This is an internal application so I haven't made any effort at all to optimize the build size. Tough to give any useful numbers because I added hx + react-dnd without removing reagent. |
Indeed, if you added react-dnd and hx at the same time it's impossible to compare. And you @Lokeh do you have some numbers? |
I don't know where to put it and this seems like the most appropriate place. All was well except for table dimensions not being locked. After a fun debug session, it turned out that I have to use I think the reason behind it is that React and Reagent have separate async rendering machinery. In the working example, |
@p-himik I think reagent has recently added support for new lifecycle methods like |
Hi, I spent the past couple days integrating hx with an existing Reagent application and thought I'd share an experience report in case it's useful to other users or to the library developers.
First, the reason I did this at all is that Reagent's development has slowed while React continues to introduce new features and idioms, and I would like to be able to use javascript libraries that use new React features like hooks without difficulty. The application currently uses re-frame and reagent.
I tried to replace a couple UIs with hx, and it ended up not being very difficult at all.
Because I have some library components for form inputs and things like that, I need to manage reagent components containing hx components and vice versa. This is pretty easy in both directions. Reagent components can return react elements, so instead of using the typical
[my-reagent-component and its args]
that you'll see a lot in reagent applications, you do(hx.react/$ my-hx-component args-as-a-map)
.The other direction requires you to use
reagent.core/as-element
. Instead of referring to the subcomponent in the usual hx way,[my-hx-component props-map]
, you use(reagent/as-element [my-reagent-component ...])
.I ended up adding some wrapper components to deal with the fact that reagent components can take any number of args but hx components just take a single props map.
I have been using https://github.com/Lokeh/reagent-context in this project for react context + reagent integration. That lib doesn't directly expose the react Context object when you create a context, so in order to use the
useContext
hook, I had to dig into the implementation details a bit:This is a re-frame project, so I've used
subscribe
anddispatch
extensively. Nothing needed to change in calls todispatch
butsubscribe
calls were replaced with calls touse-sub
, as defined here (note it's defined as<-sub
in that repo).Also, don't forget to change reagent components using the hiccup class+id shorthand to define those things in props. I don't like the #id.class syntax in hiccup, but I haven't totally gotten rid of it from my project yet.
I've ended up needing to work w/ js objects and idioms more than I would have hoped, plus I worry that the cljs<->js translation that happens w/ defnc components will eventually cause perf problems. It makes me wonder how practical/achievable it would be to modify react to allow things other than plain js objects for
props
.It's also possible I overused plain js objects because I wasn't always sure where clojurescript objects were acceptable/would perform well, like in the useState hook. IDK if that is something that hx should try to document.
I also integrated react-dnd with hx, which was easier than when I tried to use it with Reagent before. I know others have had success with a reagent and react-dnd integration via a wrapper lib, but I was able to use react-dnd without any wrapper lib at all, which is nice.
I'm pleased so far with hx, and will do future js library integrations via hx instead of reagent, and perhaps eventually replace all my reagent code with hx.
Only complaint: some of the names in hx's API are unclear.
hx.react/f
andhx.react/$
are the main offenders. I'd prefer longer, descriptive names. Especially given how infrequently those functions are used in practice.The text was updated successfully, but these errors were encountered: