1

Im fetching an array of rows from firebase, with each row looking like the one below.

row = [
    {
      index: 1,
      body: 'description'
      options: ['option1', 'option2', 'option3']
     
    }
]

I'm currently rendering these rows to a table in React as so:

{this.state.rows.map((row) => (
  <TableRow key={row.visit}>
    <TableCell align="left">{row.index}</TableCell>
    <TableCell align="left">{row.body}</TableCell>
    <TableCell align="left">{row.options}</TableCell>
  </TableRow>))}

However, I'm trying to get the options to be in a dropdown or similar, so as to look neater and not take up too much vertical space. Is there a way to map through a nested array and output it into a dropdown?

2

1 Answer 1

5

You can also map the nested data. I suggest using a select element.

{this.state.rows.map((row) => (
  <TableRow key={row.visit}>
    <TableCell align="left">{row.index}</TableCell>
    <TableCell align="left">{row.body}</TableCell>
    <TableCell align="left">
      <select>
        {row.options.map((option, i) => (
          <option key={i} value={option}>{option}</option>
        ))}
      </select>
    </TableCell>
  </TableRow>
))}
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.