ngduc / react-tabulator

React Tabulator is based on tabulator - a JS table library with many advanced features.
https://codesandbox.io/s/0mwpy612xw?module=/src/components/Home.js
MIT License
365 stars 82 forks source link

Bug: function reactFormatter uses ReactDOM.render #280

Open Tabulanga opened 1 year ago

Tabulanga commented 1 year ago

I am using React-tabulator along with Next.js. When I need to use function reactFormatter, I get an error:

next-dev.js?3515:20 Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

import { ColumnDefinition, reactFormatter, ReactTabulator } from 'react-tabulator';

const columns: ColumnDefinition[] = [
  {
    title: 'Power',
    field: 'powerState',
    formatter: reactFormatter(<PowerIcon />),
  },
];

"next": "13.2.1", "react": "18.2.0", "react-tabulator": "0.18.1"

rabbit-roger commented 1 year ago

I have the same error with React 18.

Tabulanga commented 1 year ago

@ngduc is this repository abandoned?

martin083 commented 10 months ago

I am also seeing this….any timeline on a fix? App reverts back react 17 because of this :)

aleruizj commented 9 months ago

This function serves as a workaround for the "ReactDOM.render is no longer supported in React 18" warning. By using createRoot from react-dom/client, it adheres to the new API standard introduced in React 18. Here's the updated reactFormatter function that uses createRoot for rendering components within Tabulator:

I create a PR for this fix

https://github.com/ngduc/react-tabulator/pull/287


import { createRoot } from 'react-dom/client';

function reactFormatter(JSX) {
  return function customFormatter(cell, formatterParams, onRendered) {
    onRendered(() => {
      const cellElement = cell.getElement();
      if (cellElement) {
        cellElement.innerHTML = '';
        const root = createRoot(cellElement);
        root.render(JSX);
      }
    });
    return '<div></div>';
  };
}
jojulio commented 5 months ago

any alternative to deal with this?

Tabulanga commented 5 months ago

abandoned this wrapper and use tabulator-tables directly