SolidJSS
SolidJS3y ago
9 replies
Mathieu

How to instruct a component to reset a state it holds?

I have a form looking like this (simplified code):
<Form>
  <TextField value={store.foo} />
  <Select value={store.bar} />
  <TextArea value={store.baz} />
</Form>

When submitting the form, errors can show up in red under each field. The errors are state (Signal) within the input components.

How can I reset the error state (which are signals [error, setError] = createSignal('') in each input component) to empty (back to initial value '')?

Note as to why I need this: the form is displayed in a dialog component, when the dialog closes and reopens, the form should reset to initial field values (this is easy as it is a store holding the values externally to the input components, so just need to reset the store to initial values) and not show any errors (this is where I struggle as the error is a signal within each component)
Was this page helpful?