SolidJSS
SolidJSโ€ข3y agoโ€ข
7 replies
jon vuri

How to set a store back to a default state at the top level (or clear it)?

Hi, I'm trying to use a store to represent the state of a dynamic number of inputs, where the inputs all map to a column in a db. A store seems like a good fit for this at first glance - I can store the input values keyed by the column id, and quickly get a set of signals for a dynamic number of inputs (then use those to determine form validity).

My problem is when I submit - at that point I want to reset the entire store, thus also resetting all the controlled inputs to be blank as well, in preparation for the next input. How do I do this?

For example:
const [inputs, setInputs] = createStore<Record<string, string>>({})

const updateInput = (column_id: string, value: string) => {
  setInputs({ [column_id]: value })
}

const resetInputs = () => {
  // ..?
}
Was this page helpful?