How can I solve this error:
Error: Text strings must be rendered within a <Text> component
I just try to show activityindicator by using useState hook in react native but i get error
import React, { useEffect, useState } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { Card, Avatar, IconButton } from 'react-native-paper';
import Loading from '../Loader/Loading';
const About = () => {
const [loading, setLoading] = useState(true);
useEffect(() => {
setTimeout(() => setLoading(false), 6000);
}, []);
return (
<>
{
loading ? <Loading /> :
<View style={styles.container}>
<Text>
<Card style={{ padding: 100, backgroundColor: 'white' }}>
<Card.Title title="About us" subtitle="Our profile"
left={(props) => <Avatar.Icon {...props} icon="folder" />}
right={(props) => <IconButton {...props} icon="dots-vertical" onPress={() => {}} />}
/>
<Text>This is about us page</Text>
</Card>
</Text>
</View>
};
</>
)
}
export default About;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
});
This is ActivityIndicator component which is imported on About component
import { ActivityIndicator , MD2Colors} from 'react-native-paper'
function Loading(){
return <ActivityIndicator animating={true} color={MD2Colors.red800} />
}
export default Loading;
2
Answers
The Text element can only contain text nodes or other Text elements.
You cannot nest the Card element inside a Text element.
Either remove the Text parent:
Or remove the Card child
In your example code, there is a
;
after your JSX expression. Remove it and it’ll work.