How should i render components stored in array?
arr is supposed to be signal obviously but this is pseudo code mostly. Basically I want components to be stored in array or some other concise way. So that I can add that div every two component and components have to have different props for each element in for loop.
12 Replies
Why woudl you need to do that, rather than just doing a regular render inside the <For> element? What's the use of the array in this case?
I cant use <for> afaik unless components are in array. Basically code becomes like this :
Well ok but... how are you building the array, then? Do you have data in an array or structure that you can loop on?
or is it just hardcoded data
Because if you're hardcoding an array, it makes little difference to hardcoding them in the jsx
Well its like in OP an array of components. array can be looped with <For>, but I would also need to dynamically add left and right props
Could you not make an array of values instead, then? Or if it's just repeated text, use something like
Array.from(Array(5))
and loop on that?Not sure I understand, could you post small code snippet?
That would repeat the same thing 5 times
Yeah, but I dont need to repeat same thing 5 times, Its basically hardcoded array of different components that need to be appearing in specific order, for side by side comparision
but, why not have a hardcoded array of the data needed to display the components instead of an array of components
Then loop on
componentsData
separating your data from your view is always much cleaner and easier to read in the long term
Uh, guess I did that way, if i understood correctly. type is basically the component, and it gets resolved in custom component wtih switch and match jsx
yeah that would work!
alright, thanks for your help 🙂