ReactDom.render is returning different type than what I need, how to address it ? #1188
-
Beside Markdown rendering I need to parse the html which is passed as string (ie variable import cx from 'classnames'
import 'github-markdown-css'
import 'katex/dist/katex.min.css'
import { FC, ReactNode, useEffect, useMemo, useState } from 'react'
import { CopyToClipboard } from 'react-copy-to-clipboard'
import { BsClipboard } from 'react-icons/bs'
import ReactDom from 'react-dom'
import ReactMarkdown from 'react-markdown'
import reactNodeToString from 'react-node-to-string'
import rehypeHighlight from 'rehype-highlight'
import remarkBreaks from 'remark-breaks'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
import supersub from 'remark-supersub'
import Tooltip from '../Tooltip'
import './markdown.css'
const Markdown: FC<{ children: string, isParseRequired?: boolean}> = ({ children, isParseRequired = false }) => {
return ReactDom.render(
<ReactMarkdown
remarkPlugins={[remarkMath, supersub, remarkBreaks, remarkGfm]}
rehypePlugins={[[rehypeHighlight, { detect: true, ignoreMissing: true }]]}
className={`markdown-body markdown-custom-styles !text-base font-normal`}
linkTarget="_blank"
components={{
a: ({ node, ...props }) => {
if (!props.title) {
return <a {...props} />
}
return (
<Tooltip content={props.title}>
<a {...props} title={undefined} />
</Tooltip>
)
},
code: ({ node, inline, className, children, ...props }) => {
if (inline) {
return (
<code className={className} {...props}>
{children}
</code>
)
}
return <CustomCode className={className}>{children}</CustomCode>
},
}}
children={children}/>,
document.body)
}
export default Markdown Error I am getting is : |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Hi @ishandutta2007 👋 Your issue is related to how you’re using You probably meant to write something like this: import cx from 'classnames'
import 'github-markdown-css'
import 'katex/dist/katex.min.css'
import { FC, ReactNode, useEffect, useMemo, useState } from 'react'
import { CopyToClipboard } from 'react-copy-to-clipboard'
import { BsClipboard } from 'react-icons/bs'
import ReactDom from 'react-dom'
import ReactMarkdown from 'react-markdown'
import reactNodeToString from 'react-node-to-string'
import rehypeHighlight from 'rehype-highlight'
import remarkBreaks from 'remark-breaks'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
import supersub from 'remark-supersub'
import Tooltip from '../Tooltip'
import './markdown.css'
const Markdown: FC<{ children: string, isParseRequired?: boolean}> = ({ children, isParseRequired = false }) => {
return (
<ReactMarkdown
remarkPlugins={[remarkMath, supersub, remarkBreaks, remarkGfm]}
rehypePlugins={[[rehypeHighlight, { detect: true, ignoreMissing: true }]]}
className={`markdown-body markdown-custom-styles !text-base font-normal`}
linkTarget="_blank"
components={{
a: ({ node, ...props }) => {
if (!props.title) {
return <a {...props} />
}
return (
<Tooltip content={props.title}>
<a {...props} title={undefined} />
</Tooltip>
)
},
code: ({ node, inline, className, children, ...props }) => {
if (inline) {
return (
<code className={className} {...props}>
{children}
</code>
)
}
return <CustomCode className={className}>{children}</CustomCode>
},
}}
children={children}
/>
)
}
ReactDom.render(<Markdown />, document.body) |
Beta Was this translation helpful? Give feedback.
-
@remcohaszing I may have multiple of these. One |
Beta Was this translation helpful? Give feedback.
@ishandutta2007 please read the documentation, your question is answered with examples, and discussion on how to secure it.
https://github.com/remarkjs/react-markdown#appendix-a-html-in-markdown
https://github.com/remarkjs/react-markdown#security