Create signal from store element
I have a component that takes signal as a prop:
Elsewhere I have a store that contains an array of numbers:
const [store, setStore] = createStore([1,2,3]);
My understanding is that SolidJS creates a signal for properties of stores. Is there a way to access that underlying signal so I can pass it to the input? I.e. <NumberInput value={store[0]/>
12 Replies
There is not
Typically you’d just call
props.onChange(new_value)
Not sure I understand. That sounds like a change to the implementation of the input. Elsewhere I do use signals for it so I still want to keep that interface
Either you don’t want to use stores
or that’s a bad interface
or you need some helper function
solid is designed against binding signals to components
so things won’t usually “implement Signal interface” so that could be bound this way
OK. So if you have a component that is designed to both read and write to a value you shouldn't give it a signal prop? You should give it a value and a setter function?
well how do you do this with a regular
<input>
?
you have value prop and onInput callbackSure, but html doesn't have signals - primitives for setting and reading a value
that’s still the usual pattern
so you can go from native input to a component easily
OK. Is there somewhere I can read up on this design. It strikes me as running counter to the tool (I'm sure it's not - I'm just inexperienced with Solid) so I'd like to understand why
Is the idea to maintain similarity with HTML?
That’s one reason for sure, but there are two more I think
1. solid doesn’t want “a Signal interface” but just have a function for the source
it could be reactive, it could be a memo or could be just a regular function
same with setters I guess
2. to enforce a unidirectional data flow, where the children do not write to a signal directly, but rather it happens through explicit setters that can be tracked - it’s easier to see who can write to what and who can only read
at least in theory
For the resources I think I need to find a better person to give some
OK. Thanks for the explanation. It's appreciated.
I’ve asked here maybe someone finds something .
https://discord.com/channels/722131463138705510/861229287868858379/1211065322321354772
Thanks! I'll take a look