S
Solara2mo ago
pnjun

Documentation on caching behaviour

Where can i find documentation / code examples on how solara handles component caching? I noticed that sub components are not re-rendered when their parent is re-rendered if their arguments do not change and if they are in the same order. But if the arguments or the order changes, they get redrawn I am rendering a list of components, to which i need to add in random locations. When adding to the bottom it works great, only rendering the new one, but when adding in other locations it forces a re-render of the whole list. How can i explicitly control which elements are redrawn?
4 Replies
iisakkirotko
iisakkirotko2mo ago
Hey @pnjun! You should be able to achieve this using .key() on the components. Then as long as the key and the arguments don't change the component won't be recreated. Something like:
for i in range(10):
MyComponent().key(f"component-{i}")
for i in range(10):
MyComponent().key(f"component-{i}")
Feel free to play around with this py.cafe example
PyCafe - Solara - Solara Random Card Generator
Create & Share Streamlit, Dash and Python Apps Online.
pnjun
pnjunOP5w ago
Could you explain how the .key() works? is there some documentation / link to the source i can have a look to? Thanks a lot!
MaartenBreddels
Good to hear. I've added some print statements to your code to validate that everything works as expected: https://py.cafe/maartenbreddels/solara-key-usage We don't have docs on this yet, you can read about how this works with ReactJS until then
PyCafe - Solara - Random Card Generator
Create & Share Streamlit, Dash and Python Apps Online.
Want results from more Discord servers?
Add your server