Custom State Class
Dictionaries are cool, but often a custom class will make writing our code much more enjoyable. You can add a custom state class when creating your app.
from dataclasses import dataclass
@dataclass
class State:
message: str = ""
app = Grimoire(State)
@app.page(start=True)
def start(state, second):
state.message = "Hello, traveller"
return Div(
P("Hello, Grimoire!"),
Ul(Li(link("Go to the second page", second)))
), state
@app.page()
def second(state):
return Div(
P(f"message: {state.message}")
), state