<Index> with stores

Hello there, I'm building an application where I have a store defined in a separate non-component file which I have an array of objects being stored in there and being updated on a function. I'm mapping that store using <Index> using the setup below (openWindows is the store)
<Index each={openWindows}>{(data) => <p>component goes here</p>}</Index>
<Index each={openWindows}>{(data) => <p>component goes here</p>}</Index>
It starts out as an empty array, but when I add items to the store, only the first index in the store ends up being displayed. I'm verifying this by checking the length of openWindows
<p>{openWindows().length}</p>
<p>{openWindows().length}</p>
The count goes up, but no new elements are being displayed. Any suggestions would be great :)
14 Replies
proudparrot2
proudparrot23mo ago
It's odd though, it was working earlier so I must have changed something that made it not work, but I can't find what it was
Brendonovich
Brendonovich3mo ago
out of curiosity, is there a reason you're using Index instead of For?
thetarnav
thetarnav3mo ago
If you could recreate it in playground it would help a lot. store + Index is not something people use too much so there might be a bug honestly. What happens if you replace Index with For or array.map? What happens if you remove all items again? is the old item still displayed? Also why in one example you’re calling openWindows as a function and not in the other?
proudparrot2
proudparrot23mo ago
its dealing with primitives, and the solid docs tell me to use that instead of for For isn't solving it either habit of using signals i don't use stores that often I can't get it to recreate in playground, but I can share a repo if you want
peerreynders
peerreynders3mo ago
its dealing with primitives, and the solid docs tell me
This doesn't line up with your <p>component goes here</p> As I understand it that recommendation is based on the assumption that you are rendering primitive values into the DOM, not placing entire nested components; i.e. Index moves primitive values from one text node to another. For on the other hand moves the entire DOM fragment associated with that element around within the collection wrapper.
peerreynders
peerreynders3mo ago
I could be wrong Looking at the import chain src/root.tsx src/components/windowcontainer.tsx src/lib/window.ts I suspect that the store is created before the render so it isn't actually (fully?) reactive.
GitHub
why/src/lib/windows.ts at 1b5fb8db3fc6c5b1437752eb6a7cbc0d13d7367a ...
Contribute to proudparrot2/why development by creating an account on GitHub.
GitHub
why/src/root.tsx at 1b5fb8db3fc6c5b1437752eb6a7cbc0d13d7367a · prou...
Contribute to proudparrot2/why development by creating an account on GitHub.
peerreynders
peerreynders3mo ago
I can't verify that hypothesis in the playground. It seems to be good enough to use the Accessor and SetFunction under a reactive root; creation under a reactive root doesn't seem to be a requirement.
proudparrot2
proudparrot23mo ago
okay yeah just tested .map and it's not functioning how I want it to
peerreynders
peerreynders3mo ago
Remove the Presence component and it starts working
proudparrot2
proudparrot23mo ago
interesting thank you :thumb:
peerreynders
peerreynders3mo ago
And definitely use For in this case.
proudparrot2
proudparrot23mo ago
will do
Brendonovich
Brendonovich3mo ago
By ‘primitives’ it refers to the data in the array, you have an array of objects which are not primitives. If you had an array of strings/numbers/bools Index would be more appropriate
proudparrot2
proudparrot23mo ago
I see, thank you
Want results from more Discord servers?
Add your server
More Posts
Can't find replace attribute on <Navigate />This is basically my code, I am trying to check if the user is authenticated, if not then redirect tSolid-CLI won't create any projectWhen creating using `node` (either via `npx` or `bunx`) the CLI fails simply stating 'something wentcreateEffect is reactive, JSX isn't``` export const SavedLineView = (props: { loading: Accessor<boolean> }) => { createEffect(() => {Restricte route by user role, possibly a middleware?Hello, I would appreciate some assistance from more experienced web developers, if possible. My issNavigating with A from and to dynamic route doesn't re-render.I have a dynamic route `routes/post/[postid].tsx`. Within this route I have (simplified) ```tsx consIs it possible to get createAsync to revaluate/ refetch data like createResource?I see the example [here](https://github.com/solidjs/solid-router?tab=readme-ov-file#createasync) but[solved] Can't use `@solidjs/router` in external package for SolidStartI'm trying to write a library for my SolidStart project & need to use the `A` component exported froSeems like I found a JSX bugAs long I know, you can add up variables and raw text inside a tag, something like: `<p>{myVar} peopHow can I protect nothing ever breaks, while the setTimeout is waiting```tsx createEffect(() => { if (puzzle_lala().is_revealed && is_jump_to_next_puzzle_immeCanonical way to handle exceptions in async functions to perform redirect?Hi folks, I'm very new to solid and frontend development hence my question. I have a class that talk