Reputation: 1400
I am using Atom editor for my react-native project. When I comment out my code in Atom, and run it, I will get an error saying that Text string must be rendered within a component.
I think this is Atom editor issue. I can comment out code using cmd + /
but this will throw me an error when I run the code.
class RegisterScreen extends Component {
render() {
return (
<View style={{flex:1}}>
//this is profile text
<View style={{width:'100%', height:70, justifyContent:'flex-start', alignItems:'flex-start',backgroundColor:'blue'}}>
<Text style={{paddingLeft:20, paddingTop:20, fontSize: 20, fontWeight:'bold'}}> profile </Text>
</View>
</View>
)
}
}
Upvotes: 0
Views: 540
Reputation: 12882
As others have pointed out, comments in JSX need to be enclosed by curly braces (see How to comment in JSX):
{/* A JSX comment */}
You probably would have noticed the syntax error from the highlighting, but the default JavaScript syntax package doesn't catch it. For comparison, here's how language-javascript-jsx highlights your comment:
Both packages correctly display comments enclosed by curly braces:
Consider reporting the issue, so the developers can fix the logic of the Toggle Comment command inside JSX.
Upvotes: 1
Reputation: 1291
It is an Atom editor issue. The correct way to write comments in jsx is {/*Your comment here*/}
Upvotes: 0