Replies: 7 comments 10 replies
-
If this was easy to do, it would have been the default. The problem with it is that it doesn't work with reactivity where "reading is subscribing". This relies on getters. You can't implement the subscribe part if you destructure, as the component function body never reruns. There is a community driven props destructuring plugin that rewrites your code, but I don't know how good that works. I feel like less compiler magic is better, but you have options for sure. |
Beta Was this translation helpful? Give feedback.
-
Yes, i know that reactivity is lost when destructuring, but with the help of a compiler i don't think this would be an issue, i think this is the plugin which already does it, and to me this doesn't feel like compiler magic, more like, smoothening sharp edges of solidjs to make it look more like regular js |
Beta Was this translation helpful? Give feedback.
-
Imo its magic because it (seems to) only work when having annotations on your functions which make them components. It is already pretty hard to get people who are used to react to understand reactivity. Now if you say, sometimes destructuring works, but only if you have this special annotation, that will be even more confusing. Personally, I would support this being core only if you can globally sove for this. P.S. this would be better as a discussion than an issue. As it has been brought up many times. |
Beta Was this translation helpful? Give feedback.
-
I agree. If anything this is better as a discussion. As @deluksic said unless there was some unavoidable and automatic way to identify components this would never work. And more over it would take more than just handling function signatures if you wanted any sort of consistency. The complexity there is hard to merit. Not that we are at that state now anyway. If we were to try to implement this it would make sense only to people already well aware of the problem, making the solution not any better than the problem as it interfere with teaching. Like why does certain things work and not others. It again requires too much specific knowledge. |
Beta Was this translation helpful? Give feedback.
-
If you use compiler, than it shouldn't be too hard to tell if a function uses any sort of reactivity to handle it as a reactive component, right? |
Beta Was this translation helpful? Give feedback.
-
Can you elaborate on how this would work? I'm thinking this wouldn't help, because the transform would have to re-inject prop access in order to keep reactivity. |
Beta Was this translation helpful? Give feedback.
-
I used to think that Solid's way of handling props might be a hassle. Why not just pass around Signal everywhere? I felt that destructuring, mergeProps, and splitProps were burdens. But after using solid-start for a few months, I realized it's not an issue at all. It doesn't add any burden, and I barely even notice it's there. |
Beta Was this translation helpful? Give feedback.
-
Prop destructuring is supported natively in JavaScript, and developers, often ones migrating from react to solid, are used to this pattern. Supporting it in SolidJS would lower the barrier to entry for newer developers.
This is personal opinion, but destructuring props directly in the function signature is more readable, developers can immediately see which props a component expects and uses.
And lastly, many IDEs and linters have optimizations and features that work well with destructuring, such as better autocompletion, checking for unused properties, type checking, and refactoring tools.
Personally i think the two big reasons are - lower barrier of entry and ease of use
Beta Was this translation helpful? Give feedback.
All reactions