提交一个 fetcher <form> 到服务器,无需重新加载页面。

  • 参数

    • target: SubmitTarget

      可以是多种类型的元素和对象

      HTMLFormElement

      <fetcher.Form
      onSubmit={(event) => {
      fetcher.submit(event.currentTarget);
      }}
      />

      FormData

      const formData = new FormData();
      formData.append("myKey", "myValue");
      fetcher.submit(formData, { method: "post" });

      将被序列化为 FormData 的普通对象

      fetcher.submit({ myKey: "myValue" }, { method: "post" });
      

      将被序列化为 JSON 的普通对象

      fetcher.submit(
      { myKey: "myValue" },
      { method: "post", encType: "application/json" }
      );
    • 可选options: FetcherSubmitOptions

    返回 Promise<void>