Get help from the marimo community

Updated last month

Alternative to mo.state() for Keeping Track of a List

At a glance

The community member has a list a = [] and wants to append the value of b = mo.ui.text() to a every time new text is entered into b. The community member has found a working solution using mo.state() but is looking for a better solution that doesn't require it.

Another community member suggests a solution that doesn't use mo.state(). The solution involves creating a list some_list = [] and appending the value of text_input = mo.ui.text(label="Enter") to some_list whenever the value is not empty.

Hi everyone,
Here’s what I want to do:
I have a list a = []
I also have b = mo.ui.text().
I want a to keep appending b.value every time I enter new text into b.
The only working solution I’ve found so far is using mo.state().
I’m wondering if anyone has a better solution that doesn’t require mo.state().

Thank you! 🙏
Marked as solution
Plain Text
some_list = []
text_input = mo.ui.text(label="Enter")

text_input

Plain Text
if text_input.value != "":
    some_list.append(text_input.value)

some_list


this should work without mo.state :>
View full solution
S
1 comment
Plain Text
some_list = []
text_input = mo.ui.text(label="Enter")

text_input

Plain Text
if text_input.value != "":
    some_list.append(text_input.value)

some_list


this should work without mo.state :>
Add a reply
Sign up and join the conversation on Discord