Comment JSX code in Sublime and atom

孤街浪徒 提交于 2020-01-04 03:41:49

问题


Is there any way how to comment a code inside return statement in render function in React.js (JSX) without curly brackets? It is pretty annoying to write curly brackets everytime you want to comment some piece of code.


回答1:


If you feel like you need to put too many comments, just put the block, you want to comment in external Component.




回答2:


In sublime you can setting up default comments in the following way

Create an XML file in Packages/User called Comments.tmPreferences with the following contents

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>source.jsx</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START</string>
                <key>value</key>
                <string>// </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START_2</string>
                <key>value</key>
                <string>{/* </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_END_2</string>
                <key>value</key>
                <string> */}</string>
            </dict>
        </array>
    </dict>
    <key>uuid</key>
    <string>F9BFFF1F-1999-4722-B094-52E8AFD234D1</string>
</dict>
</plist>

And after doing this you can set up comments by selecting the block and pressing Ctrl+Shift+/. this will wrap your contents within {/* */}

EDIT:

You could also make use of package like JSPrettier to format your code which will handle comments as well.




回答3:


I managed to add it to https://github.com/borela/naomi but it required many workarounds, meta scopes and a plugin.

The biggest downside is that it won't work for Atom as I used many features that are specific to sublime.



来源:https://stackoverflow.com/questions/43064715/comment-jsx-code-in-sublime-and-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!