Need click twice on button for changing state

Hello! I have two buttons in my app: Add Step and Remove Step. These buttons are supposed to remove or add text_input and selectbox by changing the session state, but I need to double click to do the action.
Code snippet:

# Use st.session_state to store the steps
    if 'steps' not in st.session_state:
        st.session_state.steps = []  # Initialize with an empty step

    for i, step in enumerate(st.session_state.steps):
        col1, col2 = st.columns(2)
        with col1:
            st.text_input(label=f"Step {i + 1}", value=step, key=f"text_step_{i}", placeholder="Input here.")

        with col2:
                label=f"Select for Step {i + 1}",
                options=["Text", "Scenario"],  # Replace with your own options

    if len(st.session_state.steps) == 0:
        st.subheader("Add step for scenario")

    add_step_button, remove_step_button = st.columns(2)
    with add_step_button:
        with stylable_container(
            button {
                background-color: #3d679f;
                color: white;
                border-color: #E8E8E8;
                if st.button("Add Step", key='add_button'):
    with remove_step_button:
        with stylable_container(
        button {
            background-color: red;
            color: white;
            border-color: #E8E8E8;
            margin-left: -240px;
            if st.button("Remove Step", key='remove_button'):
                remove_step(len(st.session_state.steps) - 1)

my function remove_step:
def remove_step(index):
if len(st.session_state.steps) > 1:

Expected behavior:
Iโ€™m facing an issue where I have to click a button twice for the action to be triggered. Itโ€™s not necessary to click the same button twice; for example, I could click the โ€œAdd stepโ€ button once, nothing happens, then I click the โ€œRemove stepโ€ button, and only then do adding the step
its working not correctly

When dealing with button issues, have a look at Button Behavior.

1 Like

thank you, st.recun() working for me

Guess you can tell me how i can create custom Edit page on clicked button?

Can you describe what that is?

Yes. I need to make the button open an editing window.

What is editing window?