Skip to content

Commit 2c6f252

Browse files
committed
Merge pull request JedWatson#23 from stepzhou/master
Add defaultValue option
2 parents 4a7e686 + db3659d commit 2c6f252

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎src/Codemirror.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ var CodeMirror = React.createClass({
2525
this.codeMirror.on('change',this.codemirrorValueChanged);
2626
this.codeMirror.on('focus',this.focusChanged.bind(this,true));
2727
this.codeMirror.on('blur',this.focusChanged.bind(this,false));
28-
this._currentCodemirrorValue=this.props.value;
29-
this.codeMirror.setValue(this.props.value);
28+
this._currentCodemirrorValue=this.props.defaultValue||this.props.value||'';
29+
this.codeMirror.setValue(this._currentCodemirrorValue);
3030
},
3131

3232
componentWillUnmount(){
@@ -37,7 +37,7 @@ var CodeMirror = React.createClass({
3737
},
3838

3939
componentWillReceiveProps(nextProps){
40-
if(this.codeMirror&&this._currentCodemirrorValue!==nextProps.value){
40+
if(this.codeMirror&&nextProps.value!==undefined&&this._currentCodemirrorValue!==nextProps.value){
4141
this.codeMirror.setValue(nextProps.value);
4242
}
4343
if(typeofnextProps.options==='object'){

0 commit comments

Comments
(0)