mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:17:00 +00:00
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 { 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>
|
||||
);
|
||||
|
@ -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') {
|
||||
|
Loading…
Reference in New Issue
Block a user