Skip to content

v3.4.1

Latest
Compare
Choose a tag to compare
@iusehooks iusehooks released this 31 Oct 16:46

Improvement:

In usetheform if a Field gets unmounted its value within the Form state gets cleared. Wrap your Field elements between the <PersistStateOnUnmount /> component to preserve the Fields values.

Example:

const Example = () => {
  const [visible, toggle] = useState(false)
  return (
    <Form>
      <PersistStateOnUnmount>
        {!visible && (
          <Collection object name="user">
            <Input type="text" name="name" value="abc" />
            <Input type="text" name="lastname" value="foo" />
          </Collection>
        )}
        <Input type="text" name="other" />
      </PersistStateOnUnmount>
      <button type="button" onClick={() => toggle(prev => !prev)}>
        Toggle Collection
      </button>
    </Form>
  )
}