Is it possible to sync state across clients or broadcast from the server? #966
Unanswered
niklas-heer
asked this question in
Question
Replies: 1 comment 7 replies
-
Hey @niklas-heer, all state is maintained server-side so this is definitely possible. So, while this is likely not realistic in a production environment, if you only run the server on a single process you could share state between clients using a global variable: poor_mans_database = {
"votes": 0
}
@component
def example():
def increment_votes():
poor_mans_database["votes"] += 1
return html.div(
html.button(
{"on_click": lambda e: increment_votes()}, "click to vote"
),
html.p("current vote total: ", poor_mans_database["votes"])
) i'm on mobile now, can get back with more detail if needed |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, I'm new to ReactPy, so I'm sorry if my question has already been answered or is obvious, but I couldn't find anything on it on the website or here in the discussion.
I want to build a simple voting app where multiple people can connect at the same time and send their vote.
I also would like to display in real time the results.
For that, I would need to sync state across multiple clients or broadcast from the server.
I tried code from the docs and seen that there is a WebSocket connection, so I guess this should be possible? (currently I'm using the FastAPI setup)
Beta Was this translation helpful? Give feedback.
All reactions