Element type is invalid: Expected String - react-native

I checked all code but didn't found the mistake which can cause such a strange error. As you see it's exported while it says you likely forget to export. Here is the code with the full list of imports:
import "expo";
import React from "react";
import {Image, TouchableHighlight} from "react-native";
import {
Content,
Left,
Right,
Icon,
CardItem,
Card,
Button,
Text,
Body,
Row,
Col,
Grid,
Thumbnail,
ScrollView
} from "native-base";
import {dataRow1,dataRow2,dataRow3,dataRow4} from "../data/HomeData";
import { primary, secondary, grey } from '../styles/variables';
const HomeContent = props => {
return (
<Content>
<ScrollView horizontal>
{dataRow1.map((item, idx) => {
return <CardItemContainer {...props} key={idx} item={item} />;
})}
</ScrollView>
<ScrollView horizontal>
{dataRow2.map((item, idx) => {
return <CardItemContainer {...props} key={idx} item={item} />;
})}
</ScrollView>
<ScrollView horizontal>
{dataRow3.map((item, idx) => {
return <CardItemContainer {...props} key={idx} item={item} />;
})}
</ScrollView>
<ScrollView horizontal>
{dataRow4.map((item, idx) => {
return <CardItemContainer {...props} key={idx} item={item} />;
})}
</ScrollView>
</Content>
);
};
const CardItemContainer = ({item, navigation}) => {
return (
<Card style={{marginBottom: 10}}>
<TouchableHighlight onPress={() => navigation.navigate("Items")}>
<CardItem cardBody>
<Image
source={item.image}
style={styles.img}
/>
</CardItem>
</TouchableHighlight>
<CardItem>
<Text style={{color:grey}}> {item.title} </Text>
</CardItem>
</Card>
);
};
const styles = {
img:{
height: 200,
width: null,
flex: 1
},
}
export default HomeContent;
What can cause it and what is wrong? Can you help me please to solve this issue?
Thanks in advance!

It looks like you have not imported any html tag reference from react-native. Every HTML tag is a element.
Let's suppose if you have Text tag then you must import it like import { Text} from react-native .

You should import ScrollView from react-native instead of native-base.
After removing ScrollView from native base import's line include it in react-native's import line like this:
import {Image, TouchableHighlight, ScrollView} from "react-native";

Related

Functional components cannot be given refs with react-native-rich-editor on Expo

I am trying to use this package :
https://www.npmjs.com/package/react-native-pell-rich-editor
And I have the following code :
import { useState, useRef } from "react";
import { RFPercentage } from "react-native-responsive-fontsize";
import BottomSheet from "#gorhom/bottom-sheet";
import {
StyleSheet,
View,
Text,
Platform,
KeyboardAvoidingView,
SafeAreaView,
ScrollView,
} from "react-native";
import {
actions,
RichEditor,
RichToolbar,
} from "react-native-pell-rich-editor";
export default function Publish() {
const postSheetRef = useRef(null);
const richText = useRef();
const snapPoints = ["90%"];
};
return (
<>
<View style={styles.container}>
<View style={styles.publishHeader}>
<Text style={styles.titleHeader}>Publier un post</Text>
</View>
<BottomSheet
ref={postSheetRef}
snapPoints={snapPoints}
handleIndicatorStyle={{ display: "none" }}
>
<View style={styles.main}>
<SafeAreaView>
<ScrollView>
<RichEditor
ref={richText}
onChange={(descriptionText) => {
console.log("descriptionText:", descriptionText);
}}
/>
</ScrollView>
<RichToolbar
editor={richText}
actions={[
actions.setBold,
actions.setItalic,
actions.setUnderline,
actions.heading1,
]}
iconMap={{
[actions.heading1]: ({ tintColor }) => (
<Text style={[{ color: tintColor }]}>H1</Text>
),
}}
/>
</SafeAreaView>
</View>
</BottomSheet>
</View>
</>
);
}
I get this error :
Functional components cannot be given refs
It concerns the Rich Editor component.
But I just followed the documentation, so I can't understand why.
I use ref with the Bottom sheet component and it works perfectly.
I am working with Expo.
How can I solve this ? This is the only package I have found that is compatible with Expo so I need to make it work ^^.
<RichEditor
ref={(r)=>{richText.current = r}}
onChange={(descriptionText) => {
console.log("descriptionText:", descriptionText);
}}
/>

Function components cannot be given refs with react-native-rich-editor on Expo

I am trying to use this package :
https://www.npmjs.com/package/react-native-pell-rich-editor
And I have the following code :
import { useState, useRef } from "react";
import { RFPercentage } from "react-native-responsive-fontsize";
import BottomSheet from "#gorhom/bottom-sheet";
import {
StyleSheet,
View,
Text,
SafeAreaView,
ScrollView,
} from "react-native";
import {
actions,
RichEditor,
RichToolbar,
} from "react-native-pell-rich-editor";
export default function Publish() {
const postSheetRef = useRef(null);
const richText = useRef();
const snapPoints = ["90%"];
};
return (
<>
<View style={styles.container}>
<View style={styles.publishHeader}>
<Text style={styles.titleHeader}>Publier un post</Text>
</View>
<BottomSheet
ref={postSheetRef}
snapPoints={snapPoints}
handleIndicatorStyle={{ display: "none" }}
>
<View style={styles.main}>
<SafeAreaView>
<ScrollView>
<RichEditor
ref={richText}
onChange={(descriptionText) => {
console.log("descriptionText:", descriptionText);
}}
/>
</ScrollView>
<RichToolbar
editor={richText}
actions={[
actions.setBold,
actions.setItalic,
actions.setUnderline,
actions.heading1,
]}
iconMap={{
[actions.heading1]: ({ tintColor }) => (
<Text style={[{ color: tintColor }]}>H1</Text>
),
}}
/>
</SafeAreaView>
</View>
</BottomSheet>
</View>
</>
);
}
I get this error :
Function components cannot be given refs
It concerns the Rich Editor component.
But I just followed the documentation, so I can't understand why.
According to the github repo of the package, RichEditor seems to be a class component ...
Anyway, the documentation tells me to use Ref.
I tried this :
<RichEditor
ref={(r)=>{richText.current = r}}
onChange={(descriptionText) => {
console.log("descriptionText:", descriptionText);
}}
/>
But it did not help.
I am working with Expo.
How can I solve this ? This is the only package I have found that is compatible with Expo so I need to make it work ^^.

Expo / TouchableOpacity onPress() not responding

I'm trying to reproduce a pomodoro app from an online course.
I've been looking at my code for several hours, going back and forth with the course, but can't find my error.
TouchableOpacity or Pressable used in RoundedButton component doesn't trigger onPress()
I tried different command to test if my logic with setStarted was flawe, without success.
Anyone can help me find my bug ?
Here is the link to the expo : https://snack.expo.dev/#battlepoap/focus-time
RoundedButton.js:
import React from 'react';
import { TouchableOpacity, Text, StyleSheet, View } from 'react-native';
export const RoundedButton = ({
style = {},
textStyle = {},
size = 125,
...props
}) => {
return (
<View>
<TouchableOpacity style={[styles(size).radius, style]}>
<Text style={[styles(size).text, textStyle]}>{props.title}</Text>
</TouchableOpacity>
</View>
);
};
const styles = (size) =>
StyleSheet.create({...});
Example with Focus.js where we add a task by pressing on the RoundedButton :
import React, { useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { TextInput } from 'react-native-paper';
import { RoundedButton } from '../../components/RoundedButton';
import { fontSizes, spacing } from '../../utils/sizes';
export const Focus = ({ addSubject }) => {
const [tempSubject, setTempSubject] = useState(null);
return (
<View style={styles.container}>
<View style={styles.titleContainer}>
<Text style={styles.title}>What do you want to focus on ?</Text>
<View style={styles.inputContainer}>
<TextInput
style={{ flex: 1, marginRight: spacing.sm }}
onSubmitEditing={({ nativeEvent }) => {
setTempSubject(nativeEvent.text);
}}
/>
<RoundedButton
size={50}
title="+"
onPress={() => addSubject = tempSubject}
/>
</View>
</View>
</View>
);
};
sic In the additional files there was ....
One thing we however need to add in order to make sure the button triggers is the onPress method. This method allows us to trigger the touch event of the user. Don't forget it!!
<TouchableOpacity style={[styles(size).radius, style]}>
<Text
style={[styles(size).text, textStyle]}
onPress={props.onPress}>
{props.title}
</Text>
</TouchableOpacity>

How to fix Require cycle warning In React Expo

I'm getting this error.[ErrorImg][1]
This is Require cycles error but I can't find what is the reason.
I want to use ListItem component to View.js through component.js and I already use that like this import {ListItem } from '../components/';.
The result is good but there is this warning and I want to fix. Please help me.
Require cycle: Components.js->
import Button from './Button';
import Select from './Select';
import Icon from './Icon';
import Tabs from './Tabs';
import Product from './Product';
import Drawer from './Drawer';
import Header from './Header';
import Switch from './Switch';
import ListItem from './ListItem';
import HorizontalListItem from './HorizontalListItem';
export {
Button,
Select,
Icon,
Tabs,
Product,
Drawer,
Header,
Switch,
ListItem,
HorizontalListItem,
};```
View.js->
```const renderPatientsList = () => {
return(
<Block style={{ paddingHorizontal: theme.SIZES.BASE }}>
<ScrollView vertical={true} showsVerticalScrollIndicator={false} style={{marginBottom: theme.SIZES.BASE * 3}}>
<ListItem product={products[0]} horizontal />
<ListItem product={products[1]} horizontal />
<ListItem product={products[2]} horizontal />
</ScrollView>
</Block>
)
}```
ListItem.js -->
```import React from 'react';
import { withNavigation } from '#react-navigation/compat';
import { StyleSheet, Dimensions, Image, TouchableWithoutFeedback } from 'react-native';
import { Block, Text, theme } from 'galio-framework';
import { Icon } from '../components/';
import { LinearGradient } from 'expo-linear-gradient';
const { width } = Dimensions.get('screen');
const ListItem = props => {
const { navigation, product, horizontal, full, style, priceColor, imageStyle, time, unReaden, weekday } = props;
const imageStyles = [styles.image, full ? styles.fullImage : styles.horizontalImage, imageStyle];
return (
<Block row={horizontal} card flex style={[styles.product, styles.shadow, style]}>
<TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
<Block style={[styles.imageContainer, styles.shadow]}>
<Image source={{ uri: product.image }} style={imageStyles}/>
</Block>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
<Block flex={3}>
<Text size={16} style={styles.userName}>{product.title}</Text>
<Block flexDirection={'row'}>
<Icon name="photo" family="font-awesome" color={theme.COLORS.MUTED} size={theme.SIZES.BASE} style={styles.icons}> </Icon>
<Icon name="check" family="font-awesome" color={theme.COLORS.MUTED} size={theme.SIZES.BASE} style={styles.icons}> </Icon>
<Text size={16} muted={!priceColor} color={priceColor}>${product.price}</Text>
</Block>
</Block>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
<Block flex={1}>
<>
{(product.time) ? (
<Text size={12} style={styles.times} color={"#06D81E"}>{product.time}</Text>
) : (
<Text size={12} style={styles.times} color={"#000"}>{product.weekday}</Text>
)}
</>
<Block style={{borderRadius: 100, backgroundColor: "#06D81E", width: theme.SIZES.BASE * 1.2, height: theme.SIZES.BASE * 1.2, position: "absolute", right: theme.SIZES.BASE, bottom: theme.SIZES.BASE}}>
<Text size={12} center style={{justifyContent: 'center', alignItems: 'center'}} color={"#FFF"} fontWeight={"semiBold"}>{product.unReaden}</Text>
</Block>
</Block>
</TouchableWithoutFeedback>
</Block>
);
}```
[1]: https://i.stack.imgur.com/rDB6i.png
You are getting require cycle warning because you end up creating a loop ( require from Component.js in ListItem.js and require from ListItem.js in Component.js)
In ListItem.js,
import {Icon} from Icon.js
The general idea is to write the module in another file and import that module from there.
see this for a detailed explanation:
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle

Background color on List Item doesn't work?

i am making a list item for the first time and noticed nothing changes if i use this code:
**EDIT!
import React from "react";
import { StyleSheet, View } from "react-native";
import { ListItem } from "react-native-elements";
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
export default class ChangePassword extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
accountIcon = () => (
<MaterialIcons name="account-box" size={35} type="MaterialIcons" />
);
changePasswordIcon = () => (
<MaterialCommunityIcons
name="textbox-password"
size={35}
type="MaterialCommunityIcons"
/>
);
render() {
return (
<View>
<ListItem title="Account" leftIcon={this.accountIcon} bottomDivider />
<View style={{ backgroundColor: "#007bff" }}>
<ListItem
title="Change password"
leftIcon={this.changePasswordIcon}
bottomDivider
/>
</View>
</View>
);
}
}
Can someone explain to me why that is and how i can fix this please.
Appreciate it, thank you for your time
You are using react-native-elements. Therefore, you must use the style of that module.
You can use containerStyle={{backgroundColor:""}}
If you just want to change the color of the title, titleStyle={{backgroundColor:""}}
Example
<ListItem
title="Change password"
leftIcon={this.changePasswordIcon}
bottomDivider
containerStyle={{backgroundColor:"blue"}}
titleStyle={{backgroundColor:"red"}}
/>
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { Avatar, ListItem } from 'react-native-elements'
const CustomList = () => {
return (
<View >
<ListItem bottomDivider containerStyle={{backgroundColor: '#3d3c3a'}} >
<Avatar
rounded
source={{uri: 'https://i.picsum.photos/id/100/2500/1656.jpg?hmac=gWyN-7ZB32rkAjMhKXQgdHOIBRHyTSgzuOK6U0vXb1w'}}
/>
<ListItem.Content>
<ListItem.Title style={{fontWeight: '800'}} >Sr.Manager</ListItem.Title>
<ListItem.Subtitle ellipsizeMode='tail' numberOfLines={1} >Hello, Welcome to</ListItem.Subtitle>
</ListItem.Content>
</ListItem>
</View>
)
}
export default CustomList;
const styles = StyleSheet.create({})