Skip to content

Commit 4b31715

Browse files
committed
fix: invalid hooks call
1 parent 5876113 commit 4b31715

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"deploy": "gh-pages -d example/build",
2323
"format": "prettier --write \"src/**/*.+(js|md|css|json|ts|tsx)\""
2424
},
25+
"peerDependencies": {
26+
"react": ">=16.8.0",
27+
"react-dom": ">=16.8.0"
28+
},
2529
"dependencies": {
2630
"lodash.debounce": "^4.0.8"
2731
},

rollup.config.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import typescript from 'rollup-plugin-typescript2'
2-
import commonjs from 'rollup-plugin-commonjs'
3-
import external from 'rollup-plugin-peer-deps-external'
4-
import resolve from 'rollup-plugin-node-resolve'
5-
import url from 'rollup-plugin-url'
1+
import typescript from 'rollup-plugin-typescript2';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import external from 'rollup-plugin-peer-deps-external';
4+
import resolve from 'rollup-plugin-node-resolve';
5+
import url from 'rollup-plugin-url';
66

7-
import pkg from './package.json'
7+
import pkg from './package.json';
88

99
export default {
1010
input: 'src/index.tsx',
@@ -22,14 +22,15 @@ export default {
2222
sourcemap: true,
2323
},
2424
],
25+
external: ['stream'],
2526
plugins: [
2627
external(),
2728
url(),
28-
resolve(),
29+
resolve({ preferBuiltins: true }),
2930
typescript({
3031
rollupCommonJSResolveHack: true,
3132
clean: true,
3233
}),
3334
commonjs(),
3435
],
35-
}
36+
};

src/HEREMap.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import debounce from 'lodash.debounce';
55
import MapContext from './utils/map-context';
66
import { HEvents, events, Events } from './utils/map-events';
77
import { usePlatform } from './hooks/use-platform';
8-
import { useScript } from 'hooks/use-script';
9-
import { useLink } from 'hooks/use-link';
8+
import { useScript } from './hooks/use-script';
9+
import { useLink } from './hooks/use-link';
1010

1111
export interface HEREMapProps extends H.Map.Options, HEvents {
1212
appId: string;
@@ -36,9 +36,11 @@ export const HEREMap: React.FC<HEREMapProps> = ({
3636
children,
3737
...rest
3838
}) => {
39-
const [map, setMap] = React.useState<H.Map>();
40-
const [behavior, setBehavior] = React.useState<H.mapevents.Behavior>();
41-
const [ui, setUi] = React.useState<H.ui.UI>();
39+
const [map, setMap] = React.useState<H.Map | undefined>(undefined);
40+
const [behavior, setBehavior] = React.useState<
41+
H.mapevents.Behavior | undefined
42+
>(undefined);
43+
const [ui, setUi] = React.useState<H.ui.UI | undefined>(undefined);
4244
const debouncedResizeMap = debounce(resizeMap, 200);
4345
const [,] = useLink(
4446
'https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1526040296',

src/Marker.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export const Marker: React.FC<MarkerProps> = ({
2424
...rest
2525
}) => {
2626
const mapContext = React.useContext(MapContext);
27-
const [marker, setMarker] = React.useState<H.map.Marker | H.map.DomMarker>();
27+
const [marker, setMarker] = React.useState<
28+
H.map.Marker | H.map.DomMarker | undefined
29+
>(undefined);
2830

2931
React.useEffect(() => {
3032
const { map, behavior } = mapContext;

src/RouteLine.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const RouteLine: React.FC<RouteLineProps> = ({
1616
lineWidth,
1717
}) => {
1818
const mapContext = React.useContext(MapContext);
19-
const [routeLine, setRouteLine] = React.useState<H.map.Polyline>();
19+
const [routeLine, setRouteLine] = React.useState<H.map.Polyline | undefined>(
20+
undefined,
21+
);
2022

2123
React.useEffect(() => {
2224
const { map } = mapContext;

src/__tests__/HEREMap.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3-
import HEREMap from 'HEREMap';
4-
import Marker from 'Marker';
5-
import RouteLine from 'RouteLine';
6-
import Circle from 'Circle';
3+
4+
import HEREMap from '../HEREMap';
5+
import Marker from '../Marker';
6+
import RouteLine from '../RouteLine';
7+
import Circle from '../Circle';
78

89
const appId = '';
910
const appCode = '';

src/hooks/use-platform.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export function usePlatform(
44
platformOptions: H.service.Platform.Options,
55
scriptsLoaded = true,
66
) {
7-
const [platform, setPlatform] = React.useState<H.service.Platform>();
7+
const [platform, setPlatform] = React.useState<
8+
H.service.Platform | undefined
9+
>(undefined);
810

911
React.useEffect(() => {
1012
if (!platform && scriptsLoaded) {

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import HEREMap from './HEREMap';
22
import Circle from './Circle';
33
import Marker from './Marker';
44
import RouteLine from './RouteLine';
5-
import { usePlatform } from 'hooks/use-platform';
5+
import { usePlatform } from './hooks/use-platform';
66

77
export { Circle, HEREMap, Marker, RouteLine, usePlatform };
88

0 commit comments

Comments
 (0)