File size: 1,033 Bytes
391a73c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useEffect, useRef } from 'react';
import { useLeafletContext } from './context.js';
import { useEventHandlers } from './events.js';
import { useLayerLifecycle } from './layer.js';
import { withPane } from './pane.js';
export function usePathOptions(element, props) {
    const optionsRef = useRef(undefined);
    useEffect(function updatePathOptions() {
        if (props.pathOptions !== optionsRef.current) {
            const options = props.pathOptions ?? {};
            element.instance.setStyle(options);
            optionsRef.current = options;
        }
    }, [
        element,
        props
    ]);
}
export function createPathHook(useElement) {
    return function usePath(props) {
        const context = useLeafletContext();
        const elementRef = useElement(withPane(props, context), context);
        useEventHandlers(elementRef.current, props.eventHandlers);
        useLayerLifecycle(elementRef.current, context);
        usePathOptions(elementRef.current, props);
        return elementRef;
    };
}