使用自定义 useFetch 挂钩发送 POST 请求并接收响应 (React.js)
Send a POST request and receive a response using custom useFetch hook (React.js)
我已使用 this website 获取 useFetch 挂钩的逻辑。我想要做的就是发送一个 post 请求,然后将请求映射到一个类型中。我知道这将是一个简单的答案,但似乎无法在网上找到任何东西!请查看上面的 link 以获取 useFetch 挂钩! :)
编辑:正文是空的,因为这只是一个例子
错误:View screenshot of error
组件:
const requestOptions = {
method: 'POST',
headers: {},
body: JSON.stringify({}),
};
const { data, error } = useFetch<ExampleType>({url, requestOptions});
UseFetch Documentation 说你需要传入一个字符串作为第一个参数,所以用
调用钩子
useFetch<ExampleType>(url, requestOptions);
我已使用 this website 获取 useFetch 挂钩的逻辑。我想要做的就是发送一个 post 请求,然后将请求映射到一个类型中。我知道这将是一个简单的答案,但似乎无法在网上找到任何东西!请查看上面的 link 以获取 useFetch 挂钩! :)
编辑:正文是空的,因为这只是一个例子
错误:View screenshot of error
组件:
const requestOptions = {
method: 'POST',
headers: {},
body: JSON.stringify({}),
};
const { data, error } = useFetch<ExampleType>({url, requestOptions});
UseFetch Documentation 说你需要传入一个字符串作为第一个参数,所以用
调用钩子useFetch<ExampleType>(url, requestOptions);