html - Content entered in the CodeMirror editor is not rendering in a preview div correctly
问题描述
I have a codemirror component on my page which looks like:
<CodeMirror
value={this.state.value}
options={options}
onBeforeChange={(editor, data, value) => {
this.setState({value: value});
}}
onChange={(editor, data, value) => {
}}
/>
I then have a button on the page, that when clicked, gets the state of the codemirror content and simply takes that value and updates my redux store. I then display the content inside of a div element like a preview of what was entered in the codemirror editor.
updatePreview() {
const { dispatch } = this.props;
console.log('calling updatePreview with value:' + this.state.value);
dispatch(EditorActions.updatePreview(this.state.value));
}
Preview is just getting the value from redux:
<div className="preview">
<h2>Preview</h2>
{editor.preview}
</div>
What I am seeing is, that if I enter HTML into the editor, it displays the HTML tags in the browser instead of the rendered element like a h1 or bold character.
Why isn't the HTML rendering correctly and it is showing the actual HTML tags instead?
解决方案
推荐阅读
- jmeter - 在 JMeter 中检查接收到的 HTTP 响应并相应地通过/失败测试
- r - 如何在 R 中使用 for 循环来创建累积计数器向量?
- r - ggplot2 自定义主题:设置绘图的默认颜色
- typescript - TypeScript - 从函数返回 2 个不同的接口
- reactjs - 使用 prevState 进行复杂的状态管理(React 17 / Create React App 4.0)
- python - 列出推导以生成以下列表
- c++ - 如何正确地为 Makefile 提供预处理器变量?
- r-exams - 如何在 NOPS 考试的标题页上隐藏考试 ID?
- typescript - 无法创建父类
- salesforce - 为什么工作流规则不适用于 Salesforce?