Props as explicit Accessors #1144
Replies: 2 comments 4 replies
-
The only problem I see here is that you're forced to treat props as "dynamic-first", which is contrary to Solid's compilation which is actually "static-first". Solid only generates getters for props that are assumed to be "dynamic". Another problem would be spreading and applying this pattern to DOM elements. Third problem would be event listeners, which are 100% static, same goes to Solid's compiler brings a lot of compile-time benefits, it helps decide Solid to not prematurely generate callbacks nor effects. But of course, users can still adopt the "accessor-first" design on their own. On top of that, there's already 3P solutions to this that would allow users to adopt this pattern. For example, https://github.com/solidjs-community/solid-primitives/tree/main/packages/destructure |
Beta Was this translation helpful? Give feedback.
-
I came to the discussions section to make this exact suggestion. The original suggestion here lays out a number of reasons I wanted to point out. The dissimilarity of As mentioned in the original suggestion, you end up with a bunch of extra code to work around this design decision ( There's also some other things that easily break because of this. For instance, I'm trying to use the HyperScript API as a JSX factory function, but prop spreads break due to this limitation (the generic JSX transform doesn't know about FWIW, the "entire- If possible, I'd really like it if there were at least some way to configure this behavior within a particular project, so a project can decide which API they'd prefer (and it'd help for things like my case with the HyperScript JSX transform). That's not the best outcome in that, with two APIs, you fragment developer understanding a little if they interact with many different projects (presumably projects they don't author, since those they do will likely be consistent with their preferences). TypeScript softens the blow with explicit props types at least. |
Beta Was this translation helpful? Give feedback.
-
Hi, I've been playing around with Solid for quite some time now. From what I have experienced and from what I have read online, I think Solid could improve the way it manages props.
The problem
Props are currently implemented as proxy objects with getters that handle the reactivity, therefore to let the reactive system intercept their usage, we have to use them inside the JSX or inside a Solid reactive primitive like createEffect/Computed/....
A possible solution
An alternative way of doing things would be to use accessors. I think this would improve DX, enabling destructuring without breaking reactivity. This would also remove the need for some of the helper functions Solid currently provides (e.g. mergeProps would just be equivalent to
{...props1, ...props2}
).As an example:
Considering that writing Accessor<...> for every prop is not ideal, some helper types could be used:
Or, imitating React.FC:
Beta Was this translation helpful? Give feedback.
All reactions