Skip to content

Commit f475b69

Browse files
Ryan DowdRyan Dowd
authored andcommitted
fix: ReactDOM.render react 18 warning
1 parent d8879bb commit f475b69

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/grid.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from "react";
22
import { Component, createRef, RefObject } from "react";
3-
import { Grid as Gridjs, UserConfig } from "gridjs";
3+
import { Grid as Gridjs, Config } from "gridjs";
44

5-
class Grid extends Component<Partial<UserConfig>, any> {
5+
class Grid extends Component<Partial<Config>, any> {
66
private wrapper: RefObject<HTMLDivElement> = createRef();
77
// Grid.js instance
88
private readonly instance = null;
@@ -18,6 +18,11 @@ class Grid extends Component<Partial<UserConfig>, any> {
1818
}
1919

2020
componentDidMount(): void {
21+
// prevent gridjs from complaining that the container is not empty
22+
if (this.wrapper.current.childNodes.length > 0) {
23+
this.wrapper.current.innerHTML = '';
24+
}
25+
2126
this.instance.render(this.wrapper.current);
2227
}
2328

src/wrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { h, createRef as gCreateRef, Component as gComponent } from "gridjs";
2-
import ReactDOM from "react-dom";
2+
import { createRoot } from "react-dom/client";
33

44

55
export class ReactWrapper extends gComponent<{
@@ -13,7 +13,8 @@ export class ReactWrapper extends gComponent<{
1313
ref = gCreateRef();
1414

1515
componentDidMount(): void {
16-
ReactDOM.render(this.props.element, this.ref.current);
16+
const root = createRoot(this.ref.current);
17+
root.render(this.props.element);
1718
}
1819

1920
render() {

0 commit comments

Comments
 (0)