Hello,
I need some help with my state in my reflex app.
Does anyone know how to share custom objects betweem states?
I have tried setting it as an attribute of my main shared state (Even though I think I read somewhere that only native python types are supported) and then calling the .get_state and accessing it from there, however when I do this strange behaviour starts happening when I call its methods.
SharedState:
from MyProcessor import MyProcessor
class SharedState(rx.State):
_my_processor: MyProcessor = MyProcessor()
In my page state:
from SharedState import SharedState
class PageState(rx.State):
list_to_process: list[str] = ["1", "2", "3"]
async def process(self):
shared_state = await self.get_state(SharedState)
shared_state.process(self.list_to_process)
When I await process I get a Var error saying that I must use rx.foreach as if the self.list_to_process has been cast to a rx.Var.
The weird thing is when I do the same thing but all in the SharedState it works fine with no errors.
Has anyone got any ideas? Is there a better weay to share my custom object between states?