S
SolidJS3mo 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
Brendonovich3mo ago
put it all in a store, each field and array element will effectively become individual signals that allow fine-grained updates
ivan
ivan3mo 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
Brendonovich3mo 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
ivan3mo ago
thanks
Want results from more Discord servers?
Add your server
More Posts
SolidStart - Nitro Module missing `context` keys in `request`Hey guys, I understand what I am asking about is likely out of scope, as this is dealing with a 3rHandle user interactions to send backendI would like to know what are methods that can handle identification of user interaction points likeHow do I use solid for reactivity without a build step?I like solid as a frontend library, and I want to use it as a "vanilla" state management library foruse directive typescript errorWhen i try to use the use: directive i get the error ```Type '{ type: string; placeholder: string; vI have to fetch initial information in a component, how do I do it?const App: Component = () => { const resp = await fetch(...); // show Home component after fDynamically creating resources based on reactive state in Solid Store**What would be the right approach to solve this using solids reactivity? ** I want to achieve the Struggling to understand the correct way to use createResource with a storeI have a global store `export const [dataStore, setDataStore] = createStore({ some: "data"}) `, whicHow do I "protect" routes? I am using @solidjs/routerNow that Outlet is not supported anymore? How do I implement a route guard for nested routes?What are canonical patterns to separate UI from domain logic in SolidJS?I am developing an app that helps guitarists to learn notes. Users learn notes by exercising. The exsolidjs createResource doesn't show error when there was an error i.e 401 Invalid credentialscreateResource data.error always false