Dynamically create cookies #5518
Unanswered
giacomochiarella
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone! I'm loving Reflex. Awesome framework! Despite this, I cannot get my head around the cookies creation, well I got it partially. I'm using Reflex 0.7.14 as frontend.
I've been able to create and update cookies but it looks like it only works if I create the cookie in advance in the state, something like this
the code above works. I have my cookie created/updated (CustomCookieManager is just a class to manage cookies in my code, the prefix is automatically added in the class and there is no Reflex code in it).
So far so good. The issue comes when I want to create a brand new cookie at runtime. A cookies that never existed before or better a list of cookies.
I thought I could create an empty list in the state and add the cookies to that list, something like this:
but this does not create the new cookies. My assumption is that it is not possible because the state is compiled in javascript and adding dynamically and element means recompile the code. Is that true? Does it mean it is not possible in any way or there is a way?
I've also noticed a similar behaviour when I tried to create a new state variable from within a state method like self.my_var = "blabla" having my_var not defined at all as attribute in the state class.
My case comes from the fact that sometimes cookies exceed the size limit. To deal with it I create the fist cookie containing info about how many pieces and I save the cookie split in multiple pieces which I rejoin when I need it.
The only solutions I found are either using reflex.LocalStorage o define in advance cookie pieces (in this last case, if the number of pieces is not enough it would be "corrupted")
Beta Was this translation helpful? Give feedback.
All reactions