Search code examples
javascripthtmlreactjsreact-table

Displaying two values but only the last one is displayed


How can I display two values e.g. name and price?

In the code below, only the price is displayed:

{
  Header: 'Price',
  accessor: (row) => row.price,
  Cell: (props) => ({
    props.value !== []
      ? props.value.map(({ name, price }) => (name && price)).join(", ")
      : ''
  })
)
},

Solution

  • props.value.map(({ name, price }) => (`${name} ${price}`)).join(", ")
    

    concatenate the strings

    name + " " + price
    

    or

    `${name} ${price}`