Not sure how I would display object contents in react native

This is how the object (‘filtered’) logs in react native-

enter image description here

I want to display each dashboardTitle in my app, however, its not showing up in the app for some reason.

I need to show dashboardTitle as in this component below-

<Text style={styles.headerText}>{filtered}</Text>

Currently, with "filtered", nothing is showing up.

Here’s the full code-

import React, { useState, useEffect, useReducer } from 'react';
import { View, Text, StyleSheet, FlatList, ActivityIndicator, Keyboard} from 'react-native';
import { Searchbar } from 'react-native-paper';
import { theme } from '../theme';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { apiStateReducer } from '../reducers/ApiStateReducer';
import CognitensorEndpoints from '../services/network/CognitensorEndpoints';
import DefaultView from '../components/default/DefaultView';
import DashboardListCard from '../components/DashboardListCard';

const AppHeader = ({
  scene,
  previous,
  navigation,
  searchIconVisible = false,
}) => {
  const [dashboards, dispatchDashboards] = useReducer(apiStateReducer, {
    data: [],
    isLoading: true,
    isError: false,
  });
  const [filtered, setFiltered] = useState();

  const setLoading = (value) => {
  const messages = dashboards.data.message.filter((item) => {
      const title = item.dashboardTitle || item.dashboardName;
      return title.toLowerCase().startsWith(value.toLowerCase());
    });
    setFiltered(messages);
    console.log(filtered);
  };
  const dropShadowStyle = styles.dropShadow;
  const toggleSearchVisibility = () => {
    navigation.navigate('Search');
  };

  useEffect(() => {
    CognitensorEndpoints.getDashboardList({
      dispatchReducer: dispatchDashboards,
    });
  }, []);

  return (
    <>
      <View style={styles.header}>
        <View style={styles.headerLeftIcon}>
          <TouchableOpacity onPress={navigation.pop}>
            {previous ? (
              <MaterialIcons
                name="chevron-left"
                size={24}
                style={styles.visible}
              />
            ) : (
              <MaterialIcons
                name="chevron-left"
                size={24}
                style={styles.invisible}
              />
              )}
          </TouchableOpacity>
        </View>
        <Text style={styles.headerText}>{filtered}</Text>
        <View style={styles.headerRightIconContainer}>
          {searchIconVisible ? (
            <TouchableOpacity
              style={[styles.headerRightIcon, dropShadowStyle]}
              onPress={toggleSearchVisibility}>
              <MaterialIcons name="search" size={24} style={styles.visible} />
            </TouchableOpacity>
          ) : (
            <View style={styles.invisible} />
          )}
        </View>
      </View>
    </>
  );
};

const styles = StyleSheet.create({
  header: {
    backgroundColor: '#FFF',
    justifyContent: 'center',
    alignItems: 'center',
    width: '100%',
    height: 60,
    flexDirection: 'row',
    padding: theme.spacing.small,
    marginTop: 30
  },
  headerText: {
    ...theme.typography.title2,
    fontWeight: '700',
  },
  headerLeftIcon: {
    marginRight: 'auto',
    padding: theme.spacing.tiny,
  },
  headerRightIconContainer: {
    marginLeft: 'auto',
  },
  headerRightIcon: {
    padding: theme.spacing.tiny,
  },
  invisible: {
    width: 40,
    color: '#FFFFFF',
  },
  visible: {
    color: '#000',
  },
  dropShadow: {
    borderRadius: 50,
    backgroundColor: 'white',
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 1,
    },
    shadowOpacity: 0.2,
    shadowRadius: 1.41,
    elevation: 2,
  },
});

export default AppHeader; 

29 thoughts on “Not sure how I would display object contents in react native”

Leave a Comment