fix(client): cannot read properties of undefined (reading 'onSuccess')
This commit is contained in:
parent
f9a18863ad
commit
145940fc6f
@ -1,5 +1,6 @@
|
|||||||
|
import { uid } from '@formily/shared';
|
||||||
import { APIClient, APIClientProvider, useAPIClient, useRequest } from '@nocobase/client';
|
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 MockAdapter from 'axios-mock-adapter';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@ -14,8 +15,8 @@ mock.onGet('/users:list').reply(async () => {
|
|||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
data: [
|
data: [
|
||||||
{ id: 1, name: 'John Smith' },
|
{ id: 1, name: uid() },
|
||||||
{ id: 2, name: 'James' },
|
{ id: 2, name: uid() },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -46,14 +47,20 @@ const ComponentA = () => {
|
|||||||
const ComponentB = () => {
|
const ComponentB = () => {
|
||||||
console.log('ComponentB');
|
console.log('ComponentB');
|
||||||
const apiClient = useAPIClient();
|
const apiClient = useAPIClient();
|
||||||
return <Button onClick={() => apiClient.service('test')?.refresh()}>刷新</Button>;
|
return (
|
||||||
|
<Space>
|
||||||
|
<Input />
|
||||||
|
<Button onClick={() => apiClient.service('test')?.run()}>提交</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
return (
|
return (
|
||||||
<APIClientProvider apiClient={apiClient}>
|
<APIClientProvider apiClient={apiClient}>
|
||||||
<ComponentB />
|
<ComponentB />
|
||||||
<br/><br/>
|
<br />
|
||||||
|
<br />
|
||||||
<ComponentA />
|
<ComponentA />
|
||||||
</APIClientProvider>
|
</APIClientProvider>
|
||||||
);
|
);
|
||||||
|
@ -18,7 +18,7 @@ type ResourceActionOptions<P = any> = {
|
|||||||
|
|
||||||
export function useRequest<P>(
|
export function useRequest<P>(
|
||||||
service: AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService,
|
service: AxiosRequestConfig<P> | ResourceActionOptions<P> | FunctionService,
|
||||||
options?: Options<any, any> & { uid?: string },
|
options: Options<any, any> & { uid?: string } = {},
|
||||||
) {
|
) {
|
||||||
const api = useContext(APIClientContext);
|
const api = useContext(APIClientContext);
|
||||||
if (typeof service === 'function') {
|
if (typeof service === 'function') {
|
||||||
|
Loading…
Reference in New Issue
Block a user