I'm trying to implement a simple iframe designmode I initiated in javascript into React. My pure js code:
<body>
<div id="textEditor">
<button id="action" title="Bold"><b>Click me</b></button>
<div id="richTextArea"></div>
<iframe id="theWYSIWYG" name="theWYSIWYG" frameborder="0"></iframe>
</div>
<script>
window.addEventListener("load", function () {
var editor = theWYSIWYG.document;
editor.designMode = 'on';
</script>
This is working of course. But trying in React:
class ExamCreate extends React.Component {
constructor(props) {
super(props);
this.examBody = null
}
state = {
modalStage: 0,
newExamName: '',
newExamDescription: '',
newExamTime: '',
}
componentDidUpdate = () => {
var a = this.examBody.document;
a.designMode = 'on';
}
and jsx:
<iframe ref={examBody => this.examBody = examBody}
id="examBody" name="examBody" frameBorder="0"></iframe>
But I cannot access the ref's document at all. How can I setup the designmode of the iframe ref?
I'm new to React and this is confusing to me why don't you wrtie this.state inside of a constructor?