Skip to content
Discussion options

You must be logged in to vote

Yes, this is possible. The general strategy is to move state which is shared by two or more components into their nearest common parent. Here's a quick example:

fromidomimportcomponent, use_state, html, run@componentdefSyncedInputs():
value, set_value=use_state("")
returnhtml.p(
Input("First input", value, set_value),
Input("Second input", value, set_value),
)
@componentdefInput(label, value, set_value):
defhandle_change(event):
set_value(event["target"]["value"])
returnhtml.label(label+" ", html.input({"value": value, "onChange": handle_change}))
run(SyncedInputs)

Note how the shared state is declared in the SyncedInputs com…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@acivitillo
Comment options

Answer selected byrmorshea
Comment options

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Category
Question
Labels
None yet
2 participants
@acivitillo@rmorshea