我使用了ahooks的useRequest ,路径和参数都对,就是失败,求解。
import { useRequest } from "ahooks";
import { Projects } from "types";
export const useEditProject = ()=>{
const {run ,...asyncResult} = useRequest((params)=>({
url: `project/${params.id}`,
method: 'PATCH',
data:params
}),{
manual: true
});
const mutates = (params:Partial<Projects>)=>{
console.log(params)
return run(params)
}
return {
mutates,
...asyncResult
}
}
//底层请求还是client
import { UseRequestProvider } from 'ahooks';
import { ReactNode } from 'react';
import { useHttp } from 'utils/http';
export const RequestProvider = ({ children }: { children: ReactNode }) => {
const client = useHttp();
return (
<UseRequestProvider
value={{
requestMethod: (param) => {
return client(param.url, { ...param });
},
}}
>
{children}
</UseRequestProvider>
);
};
登录后可查看更多问答,登录/注册
解锁 React17 高阶用法,轻松应对大型复杂长周期项目
了解课程