Hello, I'm pretty new to ClojureScript and I'd like to start a new project with it, I came across this library, how would one manage a state in helix
?
I mean. reagent
has re-frame
and atoms
, is there anything that works with helix
?
hey Eliraz! helix is meant to be a pretty small syntax wrapper around React
you can check out the docs here: https://github.com/Lokeh/helix/blob/master/docs/hooks.md#maintaining-state
those docs talk about syntax mainly. to understand managing state w/ React Hooks, this is a good starter: https://reactjs.org/docs/hooks-state.html
oh, yeah well I'm a react developer for the past 7 years. I know how to manage state in react's world. however in clojurescript I, for some reason, imagined to myself that there are solutions.
there are, you can use those too I think
can re-frame
work with helix
?
like I said, helix is meant to be a very thin wrapper. local component state works great for a majority of cases.
but I would say that being in the same position as you are, started cljs recently in a more serious manner and did lots of react before already, being able to just use hooks and functional components really simplified a lot
if you’re looking for a global state management solution, helix doesn’t have one built in other than what React gives you
re-frame can work with helix. you’ll need to write some hooks to work with it
okay I understand.
I'm just trying to figure what will work best for me and honestly I feel kind of lost, I mean if i'd like to use a library like effector
so I'll need to convert cljs to js everytime right?
I’m not sure, I haven’t used effector
is there a reason you need a global state management solution?
yes actually, the nature of my app requires some state to be globally
I mean, I could manage without a global state, I just think it will be bit of a hustle
is it something that could be handled via React Context + local state?
oh of course it could
React context is very non-efficient though, it will render every listener even if the bit that changed does not concern that listener
yeah. it’s a tradeoff: less complexity / dependencies, but worse out of the box performance
I agree with being lost w.r.t. making decisions about picking libs for managing state 😅
which is why I don’t really suggest anything other than React right now, since it’s a lot easier to migrate away from that if it becomes bad
if you start with React Context, wrapped in a custom hook, it’s easier to refactor that to use e.g. re-frame, effector, or even just a CLJS atom with a watcher
The only reason I didn't go with reagent
is that it won't leverage the functional components of react.
that’s my experience, though
@eliraz.kedmi157 If you’re willing to pre-alpha-test something, I’m working on https://github.com/orestis/reseda . The whole thing is 200-300 lines of code, so you should be able to just fork or copy the relevant bits at some point.
I dont mind trying new things, I already jumped into the rabbit hole anyways 🙂
No promises that this is even makes sense but as @lilactown says the API is what matters — you can easily replace the underlying bits.
Sure I'll give it a shot
Here’s the Reagent BMI demo, converted: https://github.com/orestis/reseda/blob/master/src/reseda/demo/bmi.cljs
We should move this discussion to #react since it’s not Helix specific.
sure
@lilactown how hard is it to write a wrapper to a js library? I mean, maybe I could wrap effector
? I really like it, I think it's really good.
i wonder how well wrapping Recoil would go
depends wholly on the JS library
and what you want the syntax to be
you can call any JS function like a CLJS function
you can create JS objects/arrays
I understand. BTW, how costly is the conversion from cljs data structures to js objects / arrays? is it being done on runtime?
helix does takes a best-effort approach to do no runtime conversion of immutable data to JS objects / arrays
when defining a component with helix, props get converted to a data type that can be used easily with destructuring/etc. without doing a recursive conversion
it uses cljs-bean: https://github.com/mfikes/cljs-bean
when creating elements, your props will get converted to a JS object automatically. if it can be done, helix will actually rewrite the props map you pass in as a JS object at compilej-time
docs here: https://github.com/Lokeh/helix/blob/master/docs/creating-elements.md
@eliraz.kedmi157 What has brought you to ClojureScript? Are there some specific problems cljs helps you to solve? You being an experienced React dev, I'd really like to hear your perspective.
are people using git deps for helix?
I’m thinking of changing my github username