fix(client): cannot read properties of undefined (reading 'onSuccess')

This commit is contained in:
chenos 2022-01-28 12:17:22 +08:00
parent f9a18863ad
commit 145940fc6f
2 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import { uid } from '@formily/shared';
import { APIClient, APIClientProvider, useAPIClient, useRequest } from '@nocobase/client';
import { Button, Table } from 'antd';
import { Button, Input, Space, Table } from 'antd';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
@ -14,8 +15,8 @@ mock.onGet('/users:list').reply(async () => {
200,
{
data: [
{ id: 1, name: 'John Smith' },
{ id: 2, name: 'James' },
{ id: 1, name: uid() },
{ id: 2, name: uid() },
],
},
];
@ -46,14 +47,20 @@ const ComponentA = () => {
const ComponentB = () => {
console.log('ComponentB');
const apiClient = useAPIClient();
return <Button onClick={() => apiClient.service('test')?.refresh()}></Button>;
return (
<Space>
<Input />
<Button onClick={() => apiClient.service('test')?.run()}></Button>
</Space>
);
};
export default () => {
return (
<APIClientProvider apiClient={apiClient}>
<ComponentB />
<br/><br/>
<br />
<br />
<ComponentA />
</APIClientProvider>
);

View File

@ -18,7 +18,7 @@ type ResourceActionOptions<P = any> = {
export function useRequest<P>(
service: AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService,
options?: Options<any, any> & { uid?: string },
options: Options<any, any> & { uid?: string } = {},
) {
const api = useContext(APIClientContext);
if (typeof service === 'function') {