Add Comments in JSX
See original GitHub issueDescribe your problem and how to reproduce it: On the “React: Add Comments in JSX” page instructions are: “Add a comment somewhere within the provided div element, without modifying the existing h1 or p elements.”
And So I entered
const JSX = (
<div> {/*test*/}
<h1>This is a block of JSX</h1>
<p>Here's a subtitle</p>
</div>
);
This doesn’t affect the h1 or p tags, and yet it fails to pass the test.
Add a Link to the page with the problem: https://learn.freecodecamp.org/front-end-libraries/react/add-comments-in-jsx
Tell us about your browser and operating system:
- Browser Name: Chrome
- Browser Version: Latest
- Operating System: MacOSX
If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >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 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 >FreeCodeCamp/add-comments-in-jsx.english.md at master
JSX is a syntax that gets compiled into valid JavaScript. Sometimes, for readability, you might need to add comments to your code.
Read more >How to write comments in React and JSX - Nathan Sebhastian
To write comments in JSX, you need to use JavaScript's forward-slash and asterisk syntax, enclosed inside a curly brace {/* comment here */}...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Like this:
div
should contain anh1
tag as the first element. testString: assert(JSX.props.children[0].type === ‘h1’ || JSX.props.children[1].type === ‘h1’, ‘Thediv
should contain anh1
tag as the first element.’);div
should contain ap
tag as the second element. testString: assert(JSX.props.children[1].type === ‘p’ || JSX.props.children[2].type === ‘p’ || JSX.props.children[3].type === ‘p’, ‘Thediv
should contain ap
tag as the second element.’);In the challenge files (this is the English version): \freeCodeCamp\curriculum\challenges\english\03-front-end-libraries\react\add-comments-in-jsx.english.md
It appears that if you add a comment on the same line as a tag with a space before it it adds it as a child. This means the tests then are looking at the wrong children. If you add a comment on a new line it’s ok. If you add a comment after a tag without a space between the tag and the comment it’s ok. I think you could test for h1 tag being child 0 or 1 and p tag being child 1, 2 or 3. Is that an acceptable test?