App input question about user defined items in a list

I am trying to allow users to add custom text to a list in an app, but i cannot figure out how to get the list defined initially, and how to get the user input to add to the list.. this is what I have been trying:

            input "customCommand", "text", title: "Enter a name for this custom command", required:false, submitOnChange:true
			if(customCommand){
				if(!customCommands){
					def customCommands = []
				}
				customCommands << "${customCommand}"
				log.debug customCommands
                // reset customCommand for another input if needed
				customCommand = null
			}
			customCommands.each{
				input "RemoveCustomCommand", "button", title: "Remove ${it}"
			}

ideally, this would end up with a list: customCommands = ["someCommand","command2","command3"]
the buttons would just display each command that the user setup, and when pressed would go to a function to execute customCommands.remove(customCommand)

the issue is I keep getting errors about customCommands being null and cannot add items to it.. similar to this error:
java.lang.NullPointerException: Cannot invoke method leftShift() on null object

Ive tried a handful of ways to get this to work, and was wondering if someone had any insight on if this is possible, and hopefully a better way to lay this out in an app preference config section.

Use state.customCommands instead of the way you're doing it. Also, use app.clearsetting("customCommand") instead of trying to assign null to.

@bravenel. thank you.. awesome. didnt even think to use state in the app even though i use it for some drivers, and for pointing out the preferred app.clearSetting(setting) method. works perfectly.

is there a way to pass a variable with the input button to be used in the appButtonHandler function? or can it only receive the name of the pushed button?

im currently using this below, and using btn.split("--") to get the customCommand out of the button press to remove, but wondering if there is a better way:

state.customCommands.each{
input "RemoveCustomCommand--${it}", "button", title: "${it} (click to remove)"
}

No, other than by using state. The way I usually do it is to use appButtonHandler to set some state variable to true when the button is pushed. And then use conditional code on the dynamic page looking for that, and one thing it does when it finds it is to clear that state variable so its not true anymore. In effect, that says do-this when the button is pushed, and that logic exists within the context of the page itself.