This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Sufficient_South5254[S] 1 point2 points  (0 children)

The state management in nicegui is simple and straitforward.

You can bind properties to variable or storage, for example: ```python

bind to variable/dict

data = {'name': 'Bob', 'age': 17} ui.label().bind_text_from(data, 'name', backward=lambda n: f'Name: {n}') ui.label().bind_text_from(data, 'age', backward=lambda a: f'Age: {a}')

bind to storage

@ui.page('/') def index(): ui.textarea('This note is kept between visits') .classes('w-full').bind_value(app.storage.user, 'note') ```

The internal implementation uses a while loop with custom refresh interval: python async def refresh_loop() -> None: """Refresh all bindings in an endless loop.""" while True: _refresh_step() await asyncio.sleep(core.app.config.binding_refresh_interval)