Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
list filter in React Native returns empty array

I retrieve some data from an API but when I filter the data to separate the values I get back an empty array...

My component:

export const RestaurantOrderScreen = () => {
  const [menuItems, setMenuItems] = useState([]);
  const [bfastItems, setBfastItems] = useState([]);
  const [lunchItems, setLunchItems] = useState([]);
  const [drinkItems, setDrinkItems] = useState([]);
  const [dinnerItems, setDinnerItems] = useState([]);

  const getAllMenuItems = async () => {
    setMenuItems([]);

    await restaurantMenuItemsApi(10000)
      .then((items) => {
        setMenuItems(items);
      })

      .catch((err) => {
        console.error(err);
      })
      .finally(() => {
        console.log("Restaurant menu items retrieved");
        filterMenuList();
      });
  };

  const filterMenuList = () => {
    console.log("Restaurant menuitems: ", menuItems);
    const bfast = menuItems.filter((item) => item.type === "BREAKFAST");
    const lunch = menuItems.filter((item) => item.type === "LUNCH");
    const dinner = menuItems.filter((item) => item.type === "DINNER");
    const drinks = menuItems.filter((item) => item.type === "DRINKS");
    const dinner = menuItems.filter((item) => item.type === "DINNER");

    setBfastItems(bfast);
    setLunchItems(lunch);
    setDrinkItems(drinks);
    setDinnerItems(dinner);

    console.log("breakfast:", bfastItems);
  };

  useEffect(() => {
    getAllMenuItems();
  }, []);

The data I get back is structured like this:

Object {
    "id": 10007,
    "menuItemByRestaurant": 10000,
    "naam": "British Breakfast",
    "price": 5.24,
    "type": "BREAKFAST",
  },

I also tried to set a timeout in the finally catch over filterMenuItems() but then I had the same result.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The best way to do is,

useEffect(() => {
   filterMenuList();
},[menuItems]}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!