Mapping props to attributes
A common pattern that comes up for me is creating components that expose the html attributes of their underlying element, while merging in their own values and defaults. For example something like this (this is not expected to work - just an example):
So my questions are:
1. Is this is a solved problem in Solid? I'm pretty new to the framework so I don't want to reinvent the wheel if there's an established idiom/library for this.
2. I'm not exactly clear on how the reactivity of props works. They don't seem to be a signal, so are they a store or do they have their own logic? When, where and how can they be modified? Should I wrap the guts of the component in a
createEffect
and expose the modified props through a signal?3 Replies
P.S. - This is what I'm using currently:
For attributes you should make use of mergeProps if you want to supply defaults for possibly undefined attributes. Otherwise just spreading them should be fine.
For classes, you'd generally use a utility library like clsx
Also props in Solid are transformed by Solid's compiler step into object getters
🙏