Skip to content

Commit

Permalink
fix(component): easymde handle defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Feb 9, 2019
1 parent 257efc2 commit b33eb44
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/client/components/EasyMDE/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class EasyMDE extends React.Component {
constructor (props) {
super(props)
this.state = {
value: ''
value: '',
loaded: false
}
}

Expand Down Expand Up @@ -53,8 +54,13 @@ class EasyMDE extends React.Component {
}

static getDerivedStateFromProps (nextProps, state) {
if (nextProps.defaultValue) {
if (state.value === '' && nextProps.defaultValue !== state.value) return { value: nextProps.defaultValue }
if (typeof nextProps.defaultValue !== 'undefined') {
if (!state.loaded && nextProps.defaultValue !== state.value)
return { value: nextProps.defaultValue, loaded: true }
} else {
return {
loaded: true
}
}

return null
Expand Down

0 comments on commit b33eb44

Please sign in to comment.