How can I set value to session state from st.components.html

Im trying to return a value from a custom html component that recreates a input text with an specific pre validation. But I cant set it afterwars into the session state. Anyone nows? I tried this:

if (value && !options.includes(value)) {{
window.parent.postMessage(
{{ type: “streamlit:setSessionState”, key: “{key}”, value }},
“*”
);
}}

If you want to create a custom component that interacts with the backend, try formally declaring the component.

Here’s a template: component-template/template/my_component at d825287aab9df1aa8168a857e2008e9dbb0c7fbd · streamlit/component-template · GitHub

The docs have a couple video tutorials: Create a Component - Streamlit Docs