Simple form submit

Create a slash command.

Simple form submit

A simple way to get all the form data without creating state for everything.

function EditUser({ user }) {
  function saveUser(ev) {
    ev.preventDefault();

    const elementsArray = [...ev.target.elements];
    const formData = elementsArray.reduce((acc, elem) => {
      if (elem.id) {
        acc[elem.id] = elem.value;
      }

      return acc;
    }, {});
  }

  // Do a 'fetch' or whatever with 'formdata'!
  // has the shape: { name: string, email: string}

  return (
    <form onSubmit={saveUser}>
      <label>
        Name
        <input type="text" id="name" defaultValue={user.name} />
      </label>

      <button>Save</button>
    </form>
  );
}