MCPcopy
hub / github.com/PaulLeCam/react-leaflet / createElementHook

Function createElementHook

packages/core/src/element.ts:24–68  ·  view source on GitHub ↗
(
  createElement: (
    props: P,
    context: LeafletContextInterface,
  ) => LeafletElement<E>,
  updateElement?: (instance: E, props: P, prevProps: P) => void,
)

Source from the content-addressed store, hash-verified

22) => RefObject<LeafletElement<E>>
23
24export function createElementHook<E, P, C = unknown>(
25 createElement: (
26 props: P,
27 context: LeafletContextInterface,
28 ) => LeafletElement<E>,
29 updateElement?: (instance: E, props: P, prevProps: P) => void,
30) {
31 if (updateElement == null) {
32 return function useImmutableLeafletElement(
33 props: P,
34 context: LeafletContextInterface,
35 ): ReturnType<ElementHook<E, P>> {
36 const elementRef = useRef<LeafletElement<E, C>>(undefined) as RefObject<
37 LeafletElement<E>
38 >
39 if (!elementRef.current)
40 elementRef.current = createElement(props, context)
41 return elementRef
42 }
43 }
44
45 return function useMutableLeafletElement(
46 props: P,
47 context: LeafletContextInterface,
48 ): ReturnType<ElementHook<E, P>> {
49 const elementRef = useRef<LeafletElement<E, C>>(undefined) as RefObject<
50 LeafletElement<E>
51 >
52 if (!elementRef.current) elementRef.current = createElement(props, context)
53 const propsRef = useRef<P>(props)
54 const { instance } = elementRef.current
55
56 useEffect(
57 function updateElementProps() {
58 if (propsRef.current !== props) {
59 updateElement(instance, props, propsRef.current)
60 propsRef.current = props
61 }
62 },
63 [instance, props, updateElement],
64 )
65
66 return elementRef
67 }
68}

Callers 10

element.tsFile · 0.90
components.tsxFile · 0.90
control.tsFile · 0.90
SVGOverlay.tsxFile · 0.90
LayersControl.tsxFile · 0.90
createControlComponentFunction · 0.85
createLayerComponentFunction · 0.85
createOverlayComponentFunction · 0.85
createPathComponentFunction · 0.85
createTileLayerComponentFunction · 0.85

Calls 1

createElementFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…