Answer the question
In order to leave comments, you need to log in
What is the best way to implement component state update in React.js for contenteditable?
The setState method calls the render method after itself , which is not critical if the behavior of the contenteditable element corresponds to the behavior of an ordinary form-input, but is critical if there are several dom elements in innerHTML at once, the cursor position is reset. The task is as follows:
1) inject any html code into the element
2) get the innerHTML value
3) apply the sanitize function to the innerHTML value
4) place the cleaned content in state.content
How to implement this?
Example:
sanitize = (content) ->
cleanContent = ''
# ...
return cleanContent
ContentEditableView = React.createClass
displayName: 'ContentEditableView'
getInitialState: -> content: ''
handleChange: (event) ->
return
render: ->
{div} = React.DOM
(div {
contentEditable: yes
onInput: @handleChange
dangerouslySetInnerHTML: {
__html: @state.content
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question