How to render a HTML comment in React?

前端 未结 4 1455
有刺的猬
有刺的猬 2020-12-09 15:27

Currently the render method can only return a single element/component. See: here

In the discussion under that ticket some suggest to wrap multiple elements returned

4条回答
  •  甜味超标
    2020-12-09 15:58

    Here's another novel approach if you need this to work with SSR.

    Here's a MaxWidth component I am using with my react-based email tool called Myza.

    import ReactDOMServer from 'react-dom/server'
    
    export const MaxWidth = ({ maxWidth = 0, className, children }: IMaxWidthProps) => {
      const renderedChildren = ReactDOMServer.renderToStaticMarkup(
        
    {children}
    ) return
    ${renderedChildren} ` }} /> }

    提交回复
    热议问题