-
Hey all. I've been playing around with porting a very simple WIP web app from Yew to Leptos. I'm most of the way there, but I've found that something which was simple in Yew, is not so simple in Leptos. Specifically, I have an API that returns one month's worth of data, and the UI is such that users can select a month to view. I'm looking to cache the results so if the user chooses month A, month B, then month A again, the same data is reused. In Yew today, I have a When I tried to port that same code over to Leptos, making the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I've got something which seems to work, but feels fragile. It has three parts:
The duplication between the first and last memo causes me unease, but this seems to work, despite being somewhat convoluted. I am all ears if there are any better ideas, or if I am way off base. |
Beta Was this translation helpful? Give feedback.
-
Why not just have a |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion. I think I got so pigeon-holed into thinking in terms of reactive elements, that I forgot I could code without them... Code seems much less brittle now. :) |
Beta Was this translation helpful? Give feedback.
Why not just have a
HashMap
where the key is the month and the value is a resource of the data for that month? It doesn't even seem like it needs to be reactive, to me; just anRc<RefCell<HashMap<_, _>>>
or, for convenience, usestore_value
and have aStoredValue<HashMap<_, _>>
? Whenever you switch months, you then use the map's entry API to either get the corresponding resource or create a new resource.