<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)
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
The count goes up, but no new elements are being displayed. Any suggestions would be great :)14 Replies
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
out of curiosity, is there a reason you're using
Index
instead of For
?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?
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
its dealing with primitives, and the solid docs tell meThis 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.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.
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.
okay
yeah just tested .map and it's not functioning how I want it to
Remove the Presence component and it starts working
interesting
thank you
:thumb:
And definitely use
For
in this case.will do
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
I see, thank you