diff --git a/packages/core-api/src/apis/ApiProvider.test.tsx b/packages/core-api/src/apis/ApiProvider.test.tsx index 255b35a0d2..ac64aca3a7 100644 --- a/packages/core-api/src/apis/ApiProvider.test.tsx +++ b/packages/core-api/src/apis/ApiProvider.test.tsx @@ -51,6 +51,35 @@ describe('ApiProvider', () => { renderedHoc.getByText('hoc message: hello'); }); + it('should provide nested access to apis', () => { + const aRef = createApiRef({ id: 'a', description: '' }); + const bRef = createApiRef({ id: 'b', description: '' }); + + const MyComponent = () => { + const a = useApi(aRef); + const b = useApi(bRef); + return ( +
+ a={a} b={b} +
+ ); + }; + + const renderedHook = render( + + + + + , + ); + renderedHook.getByText('a=z b=y'); + }); + it('should ignore deps in prototype', () => { // 100% coverage + happy typescript = hasOwnProperty + this atrocity const xRef = createApiRef({ id: 'x', description: '' }); diff --git a/packages/core-api/src/apis/ApiProvider.tsx b/packages/core-api/src/apis/ApiProvider.tsx index 1c5abf1c56..e157782024 100644 --- a/packages/core-api/src/apis/ApiProvider.tsx +++ b/packages/core-api/src/apis/ApiProvider.tsx @@ -18,16 +18,20 @@ import React, { FC, createContext, useContext, ReactNode } from 'react'; import PropTypes from 'prop-types'; import { ApiRef } from './ApiRef'; import { ApiHolder, TypesToApiRefs } from './types'; +import { ApiAggregator } from './ApiAggregator'; -type Props = { +type ApiProviderProps = { apis: ApiHolder; children: ReactNode; }; const Context = createContext(undefined); -export const ApiProvider: FC = ({ apis, children }) => { - return ; +export const ApiProvider: FC = ({ apis, children }) => { + const parentHolder = useContext(Context); + const holder = parentHolder ? new ApiAggregator(apis, parentHolder) : apis; + + return ; }; ApiProvider.propTypes = {