Streamlit app won't refresh after the button click

Hello Everyone,

I am building an app where travel to the list of questions. For that, I have two Buttons prev and next. The prev button will decrease the list index and the next button will increase it. Also, the prev button should not show if the list index is < 0 and the next button should not show if the list index is >= len(questions_list).

I have implemented the following code but the problem is the app is not refreshing properly. After clicking the next button the index will be 1 and at that time it should show the prev button. When I click the next button one more time then it shows the prev button (At this time the index is 2).

import SessionState
import streamlit as st

def app():
    state = SessionState.get(que_index=0)
    buttons_cols = st.beta_columns([1, 1, 1])
    questions = ["que1", "que2", "que3", "que4", "que5"]
    
    if state.que_index > 0:
        if buttons_cols[0].button("Prev"):
            state.que_index -= 1

    if state.que_index <= len(questions):
        if buttons_cols[1].button("Next"):
            state.que_index += 1

    st.info(f"`que_index: {state.que_index} --> {questions[state.que_index]}`")
    
    if buttons_cols[2].button("Submit"):
        pass # for now

if __name__ == "__main__":
    app()