-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathCoordinateInfo.tsx
43 lines (35 loc) · 1.07 KB
/
CoordinateInfo.tsx
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { FC } from 'react';
import _isNil from 'lodash/isNil';
import useCoordinateInfo, {
CoordinateInfoResult,
UseCoordinateInfoArgs
} from '@terrestris/react-util/dist/Hooks/useCoordinateInfo/useCoordinateInfo';
export type CoordinateInfoProps = {
/**
* The children component that should be rendered. The render prop function
* receives the state of the component (this is the clicked coordinate, the
* list of GFI features if any and the loading state).
*/
resultRenderer?: (childrenProps: CoordinateInfoResult) => React.ReactNode;
} & UseCoordinateInfoArgs;
/**
* Constructs a wrapper component for querying features from the clicked
* coordinate. The returned features can be passed to a child component
* to be visualized.
*
*/
export const CoordinateInfo: FC<CoordinateInfoProps> = ({
resultRenderer = () => <></>,
...passThroughProps
}) => {
const result = useCoordinateInfo(passThroughProps);
if (_isNil(result)) {
return null;
}
return (
<>
{resultRenderer(result)}
</>
);
};
export default CoordinateInfo;