@@ -56,20 +56,18 @@ export class SearchBox extends React.PureComponent {
56
56
)
57
57
this . containerElement = document . createElement ( `div` )
58
58
this . handleRenderChildToContainerElement ( )
59
- /*
60
- * @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox
61
- */
62
- const searchBox = new google . maps . places . SearchBox (
63
- this . containerElement . firstChild
64
- )
65
- construct ( SearchBox . propTypes , updaterMap , this . props , searchBox )
66
- this . setState ( {
67
- [ SEARCH_BOX ] : searchBox ,
68
- } )
59
+ if ( React . version . match ( / ^ 1 6 / ) ) {
60
+ return
61
+ }
62
+ this . handleInitializeSearchBox ( )
69
63
}
70
64
71
65
componentDidMount ( ) {
72
- componentDidMount ( this , this . state [ SEARCH_BOX ] , eventMap )
66
+ let searchBox = this . state [ SEARCH_BOX ]
67
+ if ( React . version . match ( / ^ 1 6 / ) ) {
68
+ searchBox = this . handleInitializeSearchBox ( )
69
+ }
70
+ componentDidMount ( this , searchBox , eventMap )
73
71
this . handleMountAtControlPosition ( )
74
72
}
75
73
@@ -98,13 +96,33 @@ export class SearchBox extends React.PureComponent {
98
96
componentWillUnmount ( ) {
99
97
componentWillUnmount ( this )
100
98
this . handleUnmountAtControlPosition ( )
99
+ if ( React . version . match ( / ^ 1 6 / ) ) {
100
+ return
101
+ }
101
102
if ( this . containerElement ) {
102
103
ReactDOM . unmountComponentAtNode ( this . containerElement )
103
104
this . containerElement = null
104
105
}
105
106
}
106
107
108
+ handleInitializeSearchBox ( ) {
109
+ /*
110
+ * @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox
111
+ */
112
+ const searchBox = new google . maps . places . SearchBox (
113
+ this . containerElement . firstChild
114
+ )
115
+ construct ( SearchBox . propTypes , updaterMap , this . props , searchBox )
116
+ this . setState ( {
117
+ [ SEARCH_BOX ] : searchBox ,
118
+ } )
119
+ return searchBox
120
+ }
121
+
107
122
handleRenderChildToContainerElement ( ) {
123
+ if ( React . version . match ( / ^ 1 6 / ) ) {
124
+ return
125
+ }
108
126
ReactDOM . unstable_renderSubtreeIntoContainer (
109
127
this ,
110
128
React . Children . only ( this . props . children ) ,
@@ -132,6 +150,12 @@ export class SearchBox extends React.PureComponent {
132
150
}
133
151
134
152
render ( ) {
153
+ if ( React . version . match ( / ^ 1 6 / ) ) {
154
+ return ReactDOM . createPortal (
155
+ React . Children . only ( this . props . children ) ,
156
+ this . containerElement
157
+ )
158
+ }
135
159
return false
136
160
}
137
161
}
0 commit comments