S
SolidJS10mo ago
ivan

how to efficiently make nested data structures in solid

Hello, I am new to Solid atm, but am aware of some reactivity principles like singals, memos, effects, etc. I was wondering what is the best way to go about implementing UI for a data structure that is nested (one of its elements is itself). For my usecase. I have an object called Questions. Each question can have sub-questions inside it , the object basically looks like this
const questions = {
body: "", //the text inside the question, e.g. "when did x happen",
id: 0, //just an id used for dynamic rendering keys,
sub_questions: [questions] // an array of sub-questions, which all have the same body, id, sub_questions fields as their parent question structure
}
const questions = {
body: "", //the text inside the question, e.g. "when did x happen",
id: 0, //just an id used for dynamic rendering keys,
sub_questions: [questions] // an array of sub-questions, which all have the same body, id, sub_questions fields as their parent question structure
}
now, in theory, the Ui for a questions body shouldn`t update when its sub_questions update, but I am having trouble understanding how to implement something like this with signals, I come from React so I have never really actually used signals, so pls help me out. Any help is appreciated thank you
5 Replies
Brendonovich
Brendonovich10mo ago
put it all in a store, each field and array element will effectively become individual signals that allow fine-grained updates
ivan
ivanOP10mo ago
is that another SolidJS API function? idk what a store is exactly, I`m assuming you mean something like this.
const question = {
body: Singal<String> //insead of just String,
id: 0,
sub_questions: [Signal<Question>] //instead of array of questions
}
const question = {
body: Singal<String> //insead of just String,
id: 0,
sub_questions: [Signal<Question>] //instead of array of questions
}
Brendonovich
Brendonovich10mo ago
yeah stores are a solid thing https://www.solidjs.com/tutorial/stores_nested_reactivity i'd recommend you go through the whole tutorial before building your own stuff
ivan
ivanOP10mo ago
thanks
Want results from more Discord servers?
Add your server