// update // 2019-9-23 原文来自 https://stackoverflow.com/questions/40015336/how-to-render-a-html-comment-in-react // Comment.jsx import React, {useEffect, useRef} from 'react'; const ReactComment = ( props ) => { const el = useRef(); useEffect( () => { el.current.outerHTML = `<!-- ${props.text} -->`; }, [] ); return ( <div ref={el}/> ); }; export default ReactComment; // Other.jsx <ReactComment text='friendship-components'/>
// update
// 2019-9-23