/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import { Result } from 'ahooks/es/useRequest/src/types'; import React, { createContext, useContext } from 'react'; import { useRequest } from '../api-client'; export const AsyncDataContext = createContext & { state?: any; setState?: any }>(null); AsyncDataContext.displayName = 'AsyncDataContext'; export interface AsyncDataProviderProps { value?: any; request?: any; uid?: string; onSuccess?: (data, params) => void; } export const AsyncDataProvider: React.FC = (props) => { const { value, request, children, ...others } = props; const result = useRequest(request, { ...others }); if (value) { return {children}; } return {children}; }; export const useAsyncData = () => { return useContext(AsyncDataContext); };