question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve commenting of JSX

See original GitHub issue

I detected some problems with jsx comments.

Uncomment doesn’t work

If I comment one line and then uncomment it, some curlybraces are being leaved behind.

before image after image should be image

Indentation spaces shouldn’t be included on the comment

before image after image should be image

Inner component is not commented if indentation spaces are not selected

If you select a component like in the next screenshot the comment shortcut doesn’t work image

Use normal javascript comments instead of jsx when the code is inside parenthesis ()

before image after image should be image

The javascript that Im using for this examples

function HelloWorld({
  greeting = "hello",
  greeted = '"World"',
  silent = false,
  onMouseOver
}) {
  if (!greeting) {
    return null;
  }

  // TODO: Don't use random in render
  let num = Math.floor(Math.random() * 1e7)
    .toString()
    .replace(/\.\d+/gi, "");

  return (
    <div
      className="HelloWorld"
      title={`You are visitor number ${num}`}
      onMouseOver={onMouseOver}
    >
      <strong>
        {greeting.slice(0, 1).toUpperCase() + greeting.slice(1).toLowerCase()}
      </strong>
      {greeting.endsWith(",") ? (
        " "
      ) : (
        <span style={{ color: "grey" }}>", "</span>
      )}
      <em>{greeted}</em>
      {silent ? "." : "!"}
    </div>
  );
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RiseOoicommented, Apr 7, 2019
1reaction
dortamiguelcommented, Mar 3, 2018

Looks Like vscode handle jsx comments very good, maybe it can be useful for some inspiration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to comment in React JSX - Wes Bos
If you use Sublime Text, I've created a little snippet so you can just type jc + TAB to get a quick comment....
Read more >
How to use comments in React - Stack Overflow
Within React(JSX), you can use {/* comment here */} , however for javascript // comment here works. So, the answer depends on where...
Read more >
Improve formatting of comments in JSX · Issue #4646 - GitHub
In JSX. Your example is something else though: A good old block with a comment inside, followed by a JSX element. That looks...
Read more >
React Native Comments - 2 Ways to Add Comments in JSX
If you want to comment a single line then you can use Double Forward Slash(//) but it can only be used outside of...
Read more >
How to write comments in ReactJS ? - GeeksforGeeks
Example 1: Comments for React Components. We can write comments in React using the double forward-slash // or the asterisk format /* */ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found