@@ -6,6 +6,7 @@ function noop() { }
6
6
class MonacoEditor extends React . Component {
7
7
constructor ( props ) {
8
8
super ( props ) ;
9
+ this . containerElement = undefined ;
9
10
this . __current_value = props . value ;
10
11
}
11
12
@@ -114,12 +115,11 @@ class MonacoEditor extends React.Component {
114
115
initMonaco ( ) {
115
116
const value = this . props . value !== null ? this . props . value : this . props . defaultValue ;
116
117
const { language, theme, options } = this . props ;
117
- const containerElement = this . refs . container ; // eslint-disable-line react/no-string-refs
118
118
const context = this . props . context || window ;
119
- if ( containerElement && typeof context . monaco !== 'undefined' ) {
119
+ if ( this . containerElement && typeof context . monaco !== 'undefined' ) {
120
120
// Before initializing monaco editor
121
121
this . editorWillMount ( context . monaco ) ;
122
- this . editor = context . monaco . editor . create ( containerElement , {
122
+ this . editor = context . monaco . editor . create ( this . containerElement , {
123
123
value,
124
124
language,
125
125
...options ,
@@ -138,6 +138,10 @@ class MonacoEditor extends React.Component {
138
138
}
139
139
}
140
140
141
+ assignRef = ( component ) => {
142
+ this . containerElement = component ;
143
+ }
144
+
141
145
render ( ) {
142
146
const { width, height } = this . props ;
143
147
const fixedWidth = width . toString ( ) . indexOf ( '%' ) !== - 1 ? width : `${ width } px` ;
@@ -146,9 +150,9 @@ class MonacoEditor extends React.Component {
146
150
width : fixedWidth ,
147
151
height : fixedHeight ,
148
152
} ;
153
+
149
154
return (
150
- // eslint-disable-next-line react/no-string-refs
151
- < div ref = "container" style = { style } className = "react-monaco-editor-container" />
155
+ < div ref = { this . assignRef } style = { style } className = "react-monaco-editor-container" />
152
156
)
153
157
}
154
158
}
0 commit comments