this is the code I wrote in react-native application and I've added the image about the error I am getting when I run the app on android virtual device.
import React from 'react';
import { Text, View } from 'react-native';
const Header = () => {
const { textStyle, viewStyle } = styles;
return (
<View style={viewStyle}>
<Text style={textStyle} >Albums!</Text>;
</View>
);
};
const styles = {
viewStyle: {
backgroundColor: '#F8F8F8'
},
textStyle: {
fontSize:20
}
};
export default Header;
The error is as follows:
Invariant Violation: Text strings must be rendered within a <Text> component.
Cœur
39k25 gold badges206 silver badges281 bronze badges
asked Jul 31, 2018 at 18:13
-
1Please post what the error is and what the desired outcome isJeremy– Jeremy2018年07月31日 18:15:27 +00:00Commented Jul 31, 2018 at 18:15
-
@JeremyLee Sir i've added the link to image to what the error isprayansh ratan– prayansh ratan2018年07月31日 18:30:04 +00:00Commented Jul 31, 2018 at 18:30
-
I don't see the link.. my edit may have overwritten yours?Jeremy– Jeremy2018年07月31日 18:37:59 +00:00Commented Jul 31, 2018 at 18:37
-
@JeremyLee Sir I've added the image again :)prayansh ratan– prayansh ratan2018年07月31日 19:18:15 +00:00Commented Jul 31, 2018 at 19:18
2 Answers 2
Just remove the semicolon which is after the text closing tag.
return (
<View style={viewStyle}>
<Text style={textStyle} >Albums!</Text> "remove this semicolon ->;"
</View>
);
answered Jul 31, 2018 at 19:27
Sign up to request clarification or add additional context in comments.
Comments
if you want that !
you can write code like this
return (
<View style={viewStyle}>
<Text style={textStyle} >{"Albums!"}</Text>
</View>
);
answered Aug 1, 2018 at 7:53
Comments
lang-js