Skip to content

Commit b35ab03

Browse files
Merge pull request #124 from yulinscottkang/r18
chore(deps): upgrade to react 18
2 parents f67869c + 7cd7bb1 commit b35ab03

15 files changed

+137
-123
lines changed

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "none",
3+
"semi": false,
4+
"singleQuote": true
5+
}

commitlint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = { extends: ['@commitlint/config-angular'] }
1+
module.exports = { extends: ['@commitlint/config-conventional'] }

package.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-azure-maps",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "React Wrapper for Azure Maps",
55
"keywords": [
66
"react",
@@ -84,12 +84,11 @@
8484
"@rollup/plugin-node-resolve": "^10.0.0",
8585
"@rollup/plugin-replace": "^2.3.4",
8686
"@testing-library/jest-dom": "^5.11.4",
87-
"@testing-library/react": "^11.1.0",
88-
"@testing-library/react-hooks": "^5.1.0",
87+
"@testing-library/react": "^13.3.0",
8988
"@testing-library/user-event": "^12.1.10",
9089
"@types/jest": "^26.0.15",
91-
"@types/react": "^17.0.39",
92-
"@types/react-dom": "^17.0.11",
90+
"@types/react": "^18.0.15",
91+
"@types/react-dom": "^18.0.6",
9392
"babel-preset-env": "^1.7.0",
9493
"concurrently": "^5.3.0",
9594
"cross-env": "^7.0.2",
@@ -98,8 +97,8 @@
9897
"lint-staged": "^10.5.2",
9998
"parcel-bundler": "1.12.3",
10099
"prettier": "^2.2.0",
101-
"react": "^17.0.2",
102-
"react-dom": "^17.0.2",
100+
"react": "^18.2.0",
101+
"react-dom": "^18.2.0",
103102
"react-scripts": "4.0.1",
104103
"rollup": "^2.33.3",
105104
"rollup-plugin-copy": "^3.4.0",
@@ -117,8 +116,8 @@
117116
"azure-maps-control": "2.0.32",
118117
"guid-typescript": "^1.0.9",
119118
"mapbox-gl": "^1.10.0",
120-
"react": "^17.0.2",
121-
"react-dom": "^17.0.2"
119+
"react": "^17.0.2 || ^18.0.0",
120+
"react-dom": "^17.0.2 || ^18.0.0"
122121
},
123122
"dependencies": {
124123
"azure-maps-control": "2.0.32",

preview/react-preview.jsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
3-
import { AzureMap, AzureMapsProvider } from '../dist/react-azure-maps.es5';
1+
import React from 'react'
2+
import { createRoot } from 'react-dom/client'
3+
import { AzureMap, AzureMapsProvider } from '../dist/react-azure-maps.es5'
44

55
const option = {
66
authOptions: {
7-
authType: "subscriptionKey",
8-
subscriptionKey: "",
9-
},
10-
};
7+
authType: 'subscriptionKey',
8+
subscriptionKey: ''
9+
}
10+
}
1111

12-
const DefaultMap= () => (
12+
const DefaultMap = () => (
1313
<AzureMapsProvider>
1414
<div style={{ height: '300px' }}>
1515
<AzureMap options={option} />
1616
</div>
1717
</AzureMapsProvider>
18-
);
18+
)
1919

20-
export default DefaultMap;
20+
export default DefaultMap
2121

22-
ReactDOM.render(<DefaultMap />, document.getElementById("root"));
22+
createRoot(document.getElementById('root')).render(<DefaultMap />)

src/components/AzureMap/useCreateMapControl.test.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { renderHook } from '@testing-library/react-hooks'
2-
import {
3-
createControl,
4-
createMapControls,
5-
createMapCustomControls
6-
} from './useCreateMapControls'
1+
import { renderHook } from '@testing-library/react'
2+
import { createControl, createMapControls, createMapCustomControls } from './useCreateMapControls'
73
import { Map } from 'azure-maps-control'
84
import { IAzureMapControls, IAzureCustomControls } from '../../types'
95

src/components/AzureMap/useCreateSprites.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import { createImageSprites } from './useCreateSprites'
33
import { Map } from 'azure-maps-control'
44

@@ -25,7 +25,7 @@ describe('createImageSprites tests', () => {
2525
)
2626
})
2727

28-
it('should create image sprintes with no icon field and not call imageSprite.add ', async () => {
28+
it('should create image sprintes with no icon field and not call imageSprite.add', async () => {
2929
const mockMap = new Map('#fake-container', {})
3030
const fakeImageSprite = {
3131
id: 'id',

src/components/AzureMapFeature/useFeature.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import atlas, { data, source } from 'azure-maps-control'
22
import { useFeature } from './useFeature'
33
import { IAzureMapFeature } from '../../types'
4-
import { renderHook } from '@testing-library/react-hooks'
4+
import { renderHook } from '@testing-library/react'
55

66
const fakePosition = new data.Point(new data.Position(0, 0))
77

src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode } from 'react'
2-
import { renderHook } from '@testing-library/react-hooks'
2+
import { renderHook } from '@testing-library/react'
33
import { Map } from 'azure-maps-control'
44
import React from 'react'
55
import { AzureMapsContext } from '../../contexts/AzureMapContext'

src/contexts/AzureMapContext.test.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useContext } from 'react'
2-
import { renderHook } from '@testing-library/react-hooks'
2+
import { renderHook } from '@testing-library/react'
3+
import { act } from 'react-dom/test-utils'
34
import { Map } from 'azure-maps-control'
45
import { AzureMapsContext, AzureMapsProvider } from '../contexts/AzureMapContext'
56

@@ -20,8 +21,10 @@ describe('AzureMapDataSourceProvider tests', () => {
2021
const { result } = renderHook(() => useContextConsumer(), {
2122
wrapper: wrapDataWithAzureMapsContext
2223
})
23-
result.current.setMapRef(mapRef)
24-
result.current.setMapReady(true)
24+
act(() => {
25+
result.current.setMapRef(mapRef)
26+
result.current.setMapReady(true)
27+
})
2528
expect(result.current.mapRef).toEqual(mapRef)
2629
})
2730

src/contexts/AzureMapDataSourceContext.test.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from 'react'
2-
import { renderHook } from '@testing-library/react-hooks'
2+
import { renderHook } from '@testing-library/react'
33
import atlas, { Map } from 'azure-maps-control'
44
import React from 'react'
55
import { AzureMapsContext } from '../contexts/AzureMapContext'
@@ -66,7 +66,9 @@ describe('AzureMapDataSourceProvider tests', () => {
6666
wrapper: wrapWithDataSourceContext({ id: 'id', dataFromUrl: 'dataFromUrl' })
6767
})
6868
expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource)
69-
expect((result.current.dataSourceRef as atlas.source.DataSource).importDataFromUrl).toHaveBeenCalledWith('dataFromUrl')
69+
expect(
70+
(result.current.dataSourceRef as atlas.source.DataSource).importDataFromUrl
71+
).toHaveBeenCalledWith('dataFromUrl')
7072
})
7173

7274
it('should call add collection if collection was not falsy', () => {
@@ -95,6 +97,8 @@ describe('AzureMapDataSourceProvider tests', () => {
9597
wrapper: wrapWithDataSourceContext({ id: 'id', options: { option: 'option' } })
9698
})
9799
expect(result.current.dataSourceRef).toBeInstanceOf(atlas.source.DataSource)
98-
expect((result.current.dataSourceRef as atlas.source.DataSource).setOptions).toHaveBeenLastCalledWith({ option: 'option' })
100+
expect(
101+
(result.current.dataSourceRef as atlas.source.DataSource).setOptions
102+
).toHaveBeenLastCalledWith({ option: 'option' })
99103
})
100104
})

src/contexts/AzureMapVectorTileSourceProvider.test.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import React, { useContext } from 'react'
33
import { Map } from 'azure-maps-control'
4-
import { IAzureVectorTileSourceStatefulProviderProps } from "../types"
4+
import { IAzureVectorTileSourceStatefulProviderProps } from '../types'
55
import { AzureMapsContext } from './AzureMapContext'
66
import { AzureMapVectorTileSourceProvider } from './AzureMapVectorTileSourceProvider'
77
import { AzureMapDataSourceContext } from '../contexts/AzureMapDataSourceContext'
@@ -32,7 +32,9 @@ const wrapWithVectorTileSourceContext = (props: IAzureVectorTileSourceStatefulPr
3232
mapRef
3333
}}
3434
>
35-
<AzureMapVectorTileSourceProvider {...{ ...props }}>{children}</AzureMapVectorTileSourceProvider>
35+
<AzureMapVectorTileSourceProvider {...{ ...props }}>
36+
{children}
37+
</AzureMapVectorTileSourceProvider>
3638
</AzureMapsContext.Provider>
3739
)
3840
}
@@ -58,12 +60,15 @@ describe('AzureMapVectorTileSourceProvider tests', () => {
5860
it('should add event to data source', () => {
5961
mapRef.events.add = jest.fn()
6062
renderHook(() => useContextConsumer(), {
61-
wrapper: wrapWithVectorTileSourceContext({ id: 'id', events: { sourceadded: (source) => {} } })
63+
wrapper: wrapWithVectorTileSourceContext({
64+
id: 'id',
65+
events: { sourceadded: (source) => {} }
66+
})
6267
})
6368
expect(mapRef.events.add).toHaveBeenCalledWith(
6469
'sourceadded',
6570
expect.any(Object),
6671
expect.any(Function)
6772
)
6873
})
69-
})
74+
})

src/hooks/useAzureMapLayer.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import atlas, { source, layer } from 'azure-maps-control'
22
import { ReactNode } from 'react'
3-
import { renderHook } from '@testing-library/react-hooks'
3+
import { renderHook } from '@testing-library/react'
44
import { useAzureMapLayer } from './useAzureMapLayer'
55
import { Map } from 'azure-maps-control'
66
import React from 'react'

src/hooks/useCheckRef.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import { useCheckRef, useCheckRefMount } from './useCheckRef'
33

44
describe('useCheckRef tests', () => {

src/types.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentClass, CSSProperties, ReactElement, StatelessComponent } from 'react'
1+
import { ComponentClass, CSSProperties, ReactElement, ReactNode, FunctionComponent } from 'react'
22
import atlas, {
33
AnimationOptions,
44
CameraBoundsOptions,
@@ -51,7 +51,7 @@ export type IAzureMap = {
5151
providedMapId?: string
5252
containerClassName?: string
5353
styles?: CSSProperties
54-
LoaderComponent?: ComponentClass<any> | StatelessComponent<any>
54+
LoaderComponent?: ComponentClass<any> | FunctionComponent<any>
5555
options?: IAzureMapOptions
5656
imageSprites?: IAzureMapImageSprite[]
5757
controls?: IAzureMapControls[]
@@ -129,7 +129,7 @@ export type IAzureMapLayerContextState = {
129129
}
130130

131131
export type IAzureDataSourceChildren =
132-
| IAzureMapFeature
132+
| (IAzureMapFeature & ReactNode)
133133
| ReactElement<IAzureMapFeature>
134134
| ReactElement<IAzureLayerStatefulProviderProps>
135135

@@ -160,9 +160,10 @@ export type IAzureMapEvent = {
160160

161161
export type IAzureDataSourceStatefulProviderProps = {
162162
id: string
163-
children?: | Array<IAzureDataSourceChildren | IAzureDataSourceChildren[] | null>
164-
| IAzureDataSourceChildren
165-
| null
163+
children?:
164+
| Array<IAzureDataSourceChildren | IAzureDataSourceChildren[] | null>
165+
| IAzureDataSourceChildren
166+
| null
166167
options?: DataSourceOptions
167168
events?: IAzureMapDataSourceEvent | any
168169
dataFromUrl?: string
@@ -177,11 +178,12 @@ export type IAzureDataSourceStatefulProviderProps = {
177178
}
178179

179180
export type IAzureVectorTileSourceStatefulProviderProps = {
180-
id: string,
181-
children?: | Array<IAzureVectorTileSourceChildren | IAzureVectorTileSourceChildren[] | null>
182-
| IAzureVectorTileSourceChildren
183-
| null
184-
options?: VectorTileSourceOptions,
181+
id: string
182+
children?:
183+
| Array<IAzureVectorTileSourceChildren | IAzureVectorTileSourceChildren[] | null>
184+
| IAzureVectorTileSourceChildren
185+
| null
186+
options?: VectorTileSourceOptions
185187
events?: IAzureMapVectorTileSourceEvent
186188
// NOTE: not sure yet why this is needed, haven't seen this used in AzureMapsDataSource, though IAzureGeoJSONDataSourceStatefulProviderProps has it
187189
index?: number

0 commit comments

Comments
 (0)