'TS1005: ',' expected. try to double map to return an object

so what im trying to achive here is that im trying to do mapping in map on component props that accept only object as it returns, i tried to use foreach but its error because the props said theres no return.

so heres my code

TS1005: ',' expected.

  data={!isEmpty(reducedCategoryExpenseData)
                                ? reducedCategoryExpenseData.map(
                                  (dataInside: any) => (
                                    {
                                      dataInside.reducedData.map((dataPrint: any) => ({
                                        x: dataPrint.month,
                                        y: `$${dataPrint.amount}`
                                      }))
                                    }
                                  )
                                )
                                : []
                            }

but it gone error on dataInside.(on this dot part)reducedData sasying TS1005: ',' expected. any ideas why? please help



Solution 1:[1]

                                 (dataInside: any) => (
                                    {
                                      dataInside.reducedData.map((dataPrint: any) => ({
                                        x: dataPrint.month,
                                        y: `$${dataPrint.amount}`
                                      }))
                                    }
                                  )

This section is returning an object because of the parentheses, like this:

something.method((param) => ({ prop: value }));

Hence the error (it expected an object expression).

Did you mean:

(dataInside: any) => dataInside.reducedData.map(...)

to return the result

Also please don't use any with TypeScript. It really defeats the main purpose.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hittingonme