Yes, if you don't modify a subtree within React then the DOM won't be touched at all. It's easy to wrap non-React functionality like a Handlebars template in React. You can either use dangerouslySetInnerHTML
:
render: function()
return <div dangerouslySetInnerHTML={{__html: template(values)}}>;
}
or you can simply return an empty div and populate (or attach event handlers, etc) it in componentDidMount:
render: function()
return <div />;
},
componentDidMount: function() {
var node = React.findDOMNode(this);
node.innerHTML = template(values);
}
In the latter case, React won't touch the DOM after the initial render because render
always returns the same thing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…