Facing issues showing HTML formatted data of draft js in UI.

huangapple go评论103阅读模式
英文:

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:

&lt;Typography variant=&quot;subtitle2&quot;&gt;
  {formikForm.values.execSummary
    ? formikForm.values.execSummary
    : &lt;div dangerouslySetInnerHTML={{__html: yourDataHere}}&gt;&lt;/div&gt;
  }
&lt;/Typography&gt;

Hope this works for you, good luck.

huangapple
  • 本文由 发表于 2023年6月27日 20:13:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定