Callbacks - how to get current control value?

In my experiments with callbacks it looks like I am always getting the state from the previous run. In the example below, if I enter ‘123’ nothing gets printed, if I change the string to ‘1234’ then ‘123’ gets printed and so on. Is this a bug and how can I access the current value (the just changed value)???

import streamlit as st

st.title('the callback function always outputs the previous string...')

def callback():
    st.text(mytext)

mytext = st.text_input('enter text',value='',on_change=callback)

ok , I figured it out myself. I more and more like the new session_state functionality!

import streamlit as st

st.title('the callback function always outputs the CURRENT string...')

def callback():

    st.text(st.session_state.mytext)

st.text_input('enter text',value='',on_change=callback,key='mytext')
1 Like