question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React fragment should't include

See original GitHub issue

Hi guys. I updated my app and catch error which didn’t appear in the past.

Updated from “react-table”: “^7.0.0-rc.15”, to “react-table”: “version”: “7.0.0”

The table uses code from the table expanded example in your’s page

<tbody {...getTableBodyProps()}>
                {rows.map((row, i) => {
                  prepareRow(row)
                  return (
                    <React.Fragment {...row.getRowProps()}>
                      <tr className={row.isExpanded ? styles.selectedRow : null}>
                        {row.cells.map((cell, index) => {
                          return (
                            <td key={index} className={cell.column.className} {...cell.getCellProps()}>{cell.render('Cell')}</td>
                          )
                        })}
                      </tr>
                      {/*
                          If the row is in an expanded state, render a row with a
                          column that fills the entire length of the table.
                        */}
                      {row.isExpanded ? (
                        <tr {...row.getRowProps()}>
                          <td colSpan={visibleColumns.length}>
                            {renderRowSubComponent(row)}
                          </td>
                        </tr>
                      ) : null}
                    </React.Fragment>
                  )
                })}
              </tbody>

The error I catch is “Warning: Invalid prop role supplied to React.Fragment. React.Fragment can only have key and children props.” Screen Shot 2020-04-06 at 1 11 18 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

19reactions
adrenalin8231commented, Jan 5, 2021

Dear future me (and everyone struggling like me),

Another example already have dealt this issue:

// L143-148
          prepareRow(row);
          const rowProps = row.getRowProps();
          return (
            // Use a React.Fragment here so the table markup is still valid
            <React.Fragment key={rowProps.key}>
              <tr {...rowProps}>

or you can just fix L77 of our example appropriately.

// L77, as-is
              <React.Fragment {...row.getRowProps()}>

// L77, to-be
              <React.Fragment key={row.getRowProps().key}>

Stay safe!

0reactions
hungdevcommented, Aug 11, 2021

@adrenalin8231,thank you, it worked. But dont forget remove {...row.getRowProps()}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragments - React
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding...
Read more >
Understanding React fragments - LogRocket Blog
Fragments are syntax that allow us to add multiple elements to a React component without wrapping them in an extra DOM node. Let's...
Read more >
React Fragments - Uses, Examples, Practices - KnowledgeHut
“ Fragments are syntax that allows us to add multiple elements to a React component without wrapping them in an extra DOM node.” ......
Read more >
React Fragments – What, Why, How - DEV Community ‍ ‍
Solution for this is, you guessed it, fragments! React fragments let you group a list of children without adding extra nodes to the...
Read more >
React: Guide to Fragments - Bits and Pieces - Bit.dev
React : Guide to Fragments. This is another post in our React Series, we have learned many React concepts in our past posts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found