Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to render component via FlatList?

$
0
0

Using react native with typescript and redux toolkit

Hi I'm bothering with render a list of messages via FlatList. By ScrollView everything rendering good but I need to implement infiniti scroll. So I'm doing something like this

const MessagesScreen = () => {  const companyId = useAppSelector(getCompanyId);  const userId = useAppSelector(getUserId);  const {    data: messages,    isLoading,    refetch  } = useGetMessagesQuery({ userId, companyId });  useFocusEffect(refetch);  return (<FlatList      data={messages}      renderItem={() => {<Messages messages={messages} />;      }}    />  );};

In return() I'm trying to render FlatList with component Messages which is down here:

const Messages = ({ messages }: { messages: Message[] }) => {  const navigation =    useNavigation<RootStackScreenProps<'DrawerNavigator'>['navigation']>();  const { colors } = useTheme();  return (<View style={styles.container}>      {messages.map(message => {        const createdAt = message.created_at;        const isRead = message.read;        const icon = isRead ? 'email-open-outline' : 'email-outline';        const onClick = () => {          navigation.navigate('Message', {            messageId: message.id          });        };        return (<TouchableOpacity key={message.id} onPress={onClick}><View              style={[styles.message, { borderBottomColor: colors.separator }]}><View style={styles.iconPart}><Icon                  name={icon}                  type="material-community"                  style={                    isRead                      ? { color: colors.separator }                      : { color: colors.inputFocus }                  }                  size={24}></Icon></View><View style={styles.bodyPart}><Text                  numberOfLines={1}                  style={[isRead ? styles.readSubject : styles.unReadSubject]}>                  {message.subject}</Text><Text                  numberOfLines={1}                  style={[isRead ? styles.readBody : styles.unReadBody]}>                  {message.body}</Text></View><View style={styles.datePart}><Text style={{ color: colors.shadow }}>                  {dayjs(createdAt).fromNow()}</Text></View></View></TouchableOpacity>        );      })}</View>  );};

Actually behaviour is just rendering white screen with error

Possible Unhandled Promise Rejection (id: 17):Error: Objects are not valid as a React child (found: object with keys {id, msg_type, created_at, subject, body, author, company_id, read}). If you meant to render a collection of children, use an array instead.

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>