Passing "up" signals in Solid
I am trying to understand how can you go by reading values from signals defined in children components in SolidJS.
I exemplified my situation in the code bellow (with a solution that I came up with but don’t know if is ideal):
I have one component that handles the content being edited (RecordEditor). The submission of the content written by the user is supposed to happens up in the hierarchy, in the AddRecordModal component. That means I need to “access the signals on the children component”.
5 Replies
Either make the signal global, in a context or in the parent component
For small numbers of signals your approach is correct, more commonly we set 2 (or 3 with default) props per signal instead of an array.
(If you want to use multiple props I'd recommend copying this utility, usage example)
Otherwise for many signals a context is easier to manage: https://docs.solidjs.com/concepts/context.
Ok! Thank you so much for the examples, that was what I was needing the most! I just didn't get what you meant by "more commonly we set 2 (or 3 with default) props per signal instead of an array."
Since those two components are directly in contact, I think context would be too much in this case so I wanted to find if there a less complex route
Instead of
title: [Accessor<string>, Setter<string>];
we set 2/3 props:
then used as:
parent component:
Ohh, ok!!
That makes sense, thanks for the example!!