useFetcher
本页内容

useFetcher

摘要

参考文档 ↗

适用于创建复杂、动态的用户界面,这些界面需要在不引起导航的情况下进行多次并发数据交互。

Fetchers 跟踪其独立的自身状态,可用于加载数据、提交表单以及与 loaders 和 actions 进行一般性交互。

import { useFetcher } from "react-router"

function SomeComponent() {
  let fetcher = useFetcher()

  // states are available on the fetcher
  fetcher.state // "idle" | "loading" | "submitting"
  fetcher.data // the data returned from the action or loader

  // render a form
  <fetcher.Form method="post" />

  // load data
  fetcher.load("/some/route")

  // submit data
  fetcher.submit(someFormRef, { method: "post" })
  fetcher.submit(someData, {
    method: "post",
    encType: "application/json"
  })
}

签名

useFetcher(options): FetcherWithComponents

参数

选项

暂无文档

文档和示例 CC 4.0