Skip to content

Commit c06a2e0

Browse files
committed
Removed string ref
1 parent 1dadb15 commit c06a2e0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function noop() { }
66
class MonacoEditor extends React.Component {
77
constructor(props) {
88
super(props);
9+
this.containerElement = undefined;
910
this.__current_value = props.value;
1011
}
1112

@@ -114,12 +115,11 @@ class MonacoEditor extends React.Component {
114115
initMonaco() {
115116
const value = this.props.value !== null ? this.props.value : this.props.defaultValue;
116117
const { language, theme, options } = this.props;
117-
const containerElement = this.refs.container; // eslint-disable-line react/no-string-refs
118118
const context = this.props.context || window;
119-
if (containerElement && typeof context.monaco !== 'undefined') {
119+
if (this.containerElement && typeof context.monaco !== 'undefined') {
120120
// Before initializing monaco editor
121121
this.editorWillMount(context.monaco);
122-
this.editor = context.monaco.editor.create(containerElement, {
122+
this.editor = context.monaco.editor.create(this.containerElement, {
123123
value,
124124
language,
125125
...options,
@@ -138,6 +138,10 @@ class MonacoEditor extends React.Component {
138138
}
139139
}
140140

141+
assignRef = (component) => {
142+
this.containerElement = component;
143+
}
144+
141145
render() {
142146
const { width, height } = this.props;
143147
const fixedWidth = width.toString().indexOf('%') !== -1 ? width : `${width}px`;
@@ -146,9 +150,9 @@ class MonacoEditor extends React.Component {
146150
width: fixedWidth,
147151
height: fixedHeight,
148152
};
153+
149154
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" />
152156
)
153157
}
154158
}

0 commit comments

Comments
 (0)