1

I want to render table, but I have a problem to render data properly.

This is just one row inside tableData array. tableData is array which contains 10 arrays like this.

 [
      { key: 'date', value: date },
      {
        key: 'opp',
        value: oppositeTeam.contestantName || '',
        handleClick: handleClick({ ...oppositeTeam, entityType: 'Team' })
      },
      { key: 'g', value: totalGoals || '' },
      { key: 'yc', value: yellowCards || '' },
      { key: 'rc', value: redCards || '' }
    ];

I am rendering table on next way:

renderTableData() {
    const { tableData } = this.state;
    const { addCustomAttribute } = this.props;

    return tableData.map((data) => (
      <tr>
        {data.map((item) => (
          <td title={item.value} key={item.id}>
            <a
               onClick={() => {
                 if (item.handleClick) item.handleClick;
               }}
            >
              {value !== null ? value : 'n/a'}
            </a>
          </td>
        ))}
      </tr>
    ));
  }

How to improve this data or logic to work together as expected?

2
  • What is the issue you are having right now with the current code? Commented May 25, 2020 at 12:49
  • Breaking error, cannot compile this Commented May 25, 2020 at 12:52

1 Answer 1

3

I think you missed item in value.

Replace

{value !== null ? value : 'n/a'}

to

{item.value !== null ? item.value : 'n/a'}

or in a short way

{item.value || 'n/a'}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.