Selectbox gives me the previous value instead of the current value

I’m trying to get the current, selected value of a selectbox. No matter what I do, when I call the value in the on_change function, it shows the previous value instead of the selected value. What’s up with that?

def updateMeeting() → None :
print(selection)

selection = st.selectbox(“Active Meeting”, options=(“one”, “two”), on_change=updateMeeting, index=None, placeholder=“Select a meeting”)

st.selectbox will return the new value in the next rerun, but the callback is called before that, so it will see the old value. In order to access the new value in the callback, assign a key to the widget and look it up in session_state.

def updateMeeting():
    print(st.session_state.selection)

selection = st.selectbox(
    "Active Meeting",
    options=("one", "two"),
    on_change=updateMeeting,
    index=None,
    placeholder=“Select a meeting”,
    key="selection"
)