// @flow import hoistNonReactStatics from 'hoist-non-react-statics' import React, { createContext, forwardRef, useContext, type AbstractComponent, } from 'react' import type { LeafletContext } from './types' const leafletContext = createContext({}) export const useLeaflet = (): LeafletContext => useContext(leafletContext) export const LeafletConsumer = leafletContext.Consumer export const LeafletProvider = leafletContext.Provider export const withLeaflet = ( WrappedComponent: AbstractComponent, ): AbstractComponent<$Diff, Instance> => { const WithLeafletComponent = (props, ref) => ( {(leaflet: LeafletContext) => ( )} ) const name = // flowlint-next-line sketchy-null-string:off WrappedComponent.displayName || WrappedComponent.name || 'Component' WithLeafletComponent.displayName = `Leaflet(${name})` const LeafletComponent = forwardRef(WithLeafletComponent) hoistNonReactStatics(LeafletComponent, WrappedComponent) return LeafletComponent }