Search code examples
javascriptreactjsarraysjsonredux

API to data for react/redux js


I have the following API :

{
  list_A: [ ],
  list_B: [ ],
  list_C: {},
}

How can I map the data to display the category from Redux state : list_A, list_B, list_C, and not the dates inside.

I used JSON.parse(listType) but it didn't work

  const listType = useSelector((state) => state.orderReducer);
  {listType.map((type) => console.log(type))}

Result: ERROR listType.map is not a function TypeError: listType.map is not a function

Thank you


Solution

  • Is this what you are looking for?

    const categories = {
      list_A: [],
      list_B: [],
      list_C: {},
    }
    console.log(Object.keys(categories))