Search code examples
javascriptantdmap-function

Ant design - Object.map inside Collapse Panel is not working


I have a list of objects like this:

{CategoryName: "Production age", CategoryValue: [1997, 1996, 1992, 1991, 1995, 1990, 1993]}
{CategoryName: "Mileage (km)" CategoryValue:[75213", "351255", "2150", "275000", "5000", "23125", "125000", "14500", "75000", "295312", "31250", "123000", "240000"]

I want to map CategoryName to a panel, and CategoryValues to Row elements. For me it seems that I have done it right, but somehow is not working. Can somebody please explain what am I doing wrong? Thank you

My code:

<Collapse>
 {renderFiltering}
</Collapse>}

const renderFiltering = MainCategory.map((filter, index)  => {
        return (
        <Panel header={filter.CategoryName} key={filter.CategoryName}>
              {renderFilterValues(filter.CategoryValue)}
              
        </Panel>
    )})

const renderFilterValues = (filterValues) => {
       filterValues.map((values) => {
            return (
                <Row>
                    {values}
               </Row>
            )})
    }

Solution

  • I think you've a missing return in your const renderFilterValues since it's a function, otherwise it'll return nothing

    const renderFilterValues = (filterValues) => {
      // added return
      return filterValues.map((values) => {
        return (
          <Row>
            {values}
          </Row>
        )
      })
    }