英文:
Facing issues showing HTML formatted data of draft js in UI
问题
I am facing an issue showing my text in HTML format you can see below I am getting output correctly from the editor but when I display this text in my UI that style is not getting applied
Getting output in this format
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book.
<strong>It has survived not only five centuries.</strong>
</p>\n
This is onChange
const onChange = (newEditorState) => {
setEditorState(newEditorState);
setContent(
draftToHtml(convertToRaw(newEditorState.getCurrentContent()))
);
};
<Box
mt={2}
display="flex"
justifyContent="space-between"
alignItems="center"
>
<Box>
<Typography variant="subtitle2">
{formikForm.values.dta
? formikForm.values.dta
: 'Add data here.'
}
</Typography>
</Box>
</Box>
英文:
I am facing an issue showing my text in HTML format you can see below I am getting output correctly from the editor but when I display this text in my UI that style is not getting applied
Getting output in this format
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book.
<strong>It has survived not only five centuries.</strong>
</p>\n
This is onChange
const onChange = (newEditorState) => {
setEditorState(newEditorState);
setContent(
draftToHtml(convertToRaw(newEditorState.getCurrentContent()))
);
};
<Box
mt={2}
display="flex"
justifyContent="space-between"
alignItems="center"
>
<Box>
<Typography variant="subtitle2">
{formikForm.values.dta
? formikForm.values.dta
: 'Add data here.'
}
</Typography>
</Box>
</Box>
答案1
得分: 1
你可以尝试这样在你的组件中显示HTML:
<Typography variant="subtitle2">
{formikForm.values.execSummary
? formikForm.values.execSummary
: <div dangerouslySetInnerHTML={{__html: yourDataHere}}></div>
}
</Typography>
希望对你有帮助,祝好运。
英文:
You can try this to display html in your component:
<Typography variant="subtitle2">
{formikForm.values.execSummary
? formikForm.values.execSummary
: <div dangerouslySetInnerHTML={{__html: yourDataHere}}></div>
}
</Typography>
Hope this works for you, good luck.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论