Create signal from store element

I have a component that takes signal as a prop:
const NumberInput:Component<{value:Signal<number>}> = props => {
// Stuff...
return <input>{some fancy business}</input>
}
const NumberInput:Component<{value:Signal<number>}> = props => {
// Stuff...
return <input>{some fancy business}</input>
}
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
thetarnav
thetarnav11mo ago
There is not Typically you’d just call props.onChange(new_value)
Ghirigoro
GhirigoroOP11mo ago
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
thetarnav
thetarnav11mo ago
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
Ghirigoro
GhirigoroOP11mo ago
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?
thetarnav
thetarnav11mo ago
well how do you do this with a regular <input>? you have value prop and onInput callback
Ghirigoro
GhirigoroOP11mo ago
Sure, but html doesn't have signals - primitives for setting and reading a value
thetarnav
thetarnav11mo ago
that’s still the usual pattern so you can go from native input to a component easily
Ghirigoro
GhirigoroOP11mo ago
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?
thetarnav
thetarnav11mo ago
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
Ghirigoro
GhirigoroOP11mo ago
OK. Thanks for the explanation. It's appreciated.
Ghirigoro
GhirigoroOP11mo ago
Thanks! I'll take a look
Want results from more Discord servers?
Add your server