UNPKG

@yandex/ymaps3-types

Version:

Types for ymaps3 maps library

51 lines (50 loc) 1.58 kB
import { YMapGroupEntity } from "../YMapEnities"; import type { Context } from "../Entities"; /** * YMapContextProvider props */ export type YMapContextProviderProps<T> = { /** Context that will receive the provided value */ context: Context<T>; /** Value to be provided in the context. */ value: T; }; /** * Context provider for YMap, allowing to inject a context and its value. * * ```javascript * const mapContextProvider = new YMapContextProvider({context: SomeMapContext, value: {your: 'value'}}); * map.addChild(mapContextProvider); * ``` * And define context consumer: * ```ts * class SomeContextConsumer extends ymaps3.YMapEntity<{}> { * constructor() { * super({}); * } * * _onAttach() { * const value = this._consumeContext(SomeMapContext); * console.log(value); // {your: 'value'} * } * } * ``` * When adding nested containers, the context will be available in them: * ```ts * mapContextProvider.addChild(new SomeContextConsumer()); * ``` * But the most important thing is that the context can be passed at any nesting level: * ```tsx * <YMapContextProvider context={SomeMapContext} value={{your: 'value'}}> * <YMapContainer> * <YMapContainer> * <SomeContextConsumer /> * <YMapContainer> * </YMapContainer> * </YMapContextProvider> * ``` */ export declare class YMapContextProvider<T> extends YMapGroupEntity<YMapContextProviderProps<T>> { protected _onAttach(): void; protected _onUpdate({ value }: Partial<YMapContextProviderProps<T>>): void; }