Replies: 4 comments
-
You can simply use a global store: const [comments, setComments] = createRoot(() => createStore([]));
export { comments, setComments }; Then, you can import it in the file and use it as if it was local state. |
Beta Was this translation helpful? Give feedback.
-
Hello, Thanks for your fast and helpful response. I am assuming that this state will just store all comments. But how do I fetch the right comments for a given post id? Example, I opened post1 and load all the comments of post1 into this state. Then I open post2, I am assuming that if I request for comments from this store, it will give me the comments in it even though the comments are not for post2. Again, I am assuming. But please kindly share more light on how this store will allow me fetch the right comments for a given post id. Thanks. |
Beta Was this translation helpful? Give feedback.
-
That really depends on the data structure you choose. You can either use array.find() to select the post or more efficiently, store an object with post IDs and references to the post objects in the array. |
Beta Was this translation helpful? Give feedback.
-
Yeah. I have done that kind of thing. I was just thinking solidJs have a state management that handles state like recoil. Thanks very much. I really appreciate. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
First of all, thanks for the great effort and engineering of this project. It is really a smart move. And I really want to use solidjs to build the next version of my production social network. Which I planned to be a great improvement to the current version running already.
This is not really an issue. I already have a huge application designed in reactjs which is currently running on https://minitte.com
However, I want to redesign the v2.0 using solidjs based on what I have read about solidjs so far. So, I need to put down my checklist.
On the current application, I am using Recoil to manage global state and with the library, I can use atomFamily to store related states by key.
For example:
But I am not able to see how to do something like that with solidjs. I know that I can manage state globally with solidjs. But I want to be able to save related state using keys.
Functionalities like this is helpful to use one state to hold comments for different posts.
I'll be happy if anyone can be of help. Maybe I am missing a part of solidjs documentation.
Thanks
Your Example Website or App
https://recoiljs.org/docs/api-reference/utils/atomFamily/
Steps to Reproduce the Bug or Issue
Go to example section in the page
Expected behavior
N/A
Screenshots or Videos
No response
Platform
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions