react 中的注释怎么写呢?{/**/}这个不好使呀~

我最终想要的效果是这样
clipboard.png

而我写的时候他被编译成了react-text这是啥东西?按理说不应该显示为<!-- hfkdshk -->这样的么?
clipboard.png

阅读 30.6k
4 个回答

// 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'/>

这是 JSX。

不要在里面写注释。

{/* jsx */} 单行注释

{/*
    多行注释   
*/}
推荐问题