Skip to content

Commit

Permalink
fix: useEffect cleanup not executed when re-executing cell (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobuikhuizen authored Dec 19, 2023
1 parent 85467fe commit 06305c6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MODULE_NAME, MODULE_VERSION } from './version';
// import 'es-module-shims';
import { transform } from 'sucrase';
import { ErrorBoundary } from './components';
import { Root } from "react-dom/client";


// @ts-ignore
Expand Down Expand Up @@ -108,6 +109,8 @@ export class ReactModel extends DOMWidgetModel {


export class ReactView extends DOMWidgetView {
private root: Root | null = null;

render() {
this.el.classList.add('jupyter-react-widget');
// using babel is a bit of an art, so leaving this code for if we
Expand Down Expand Up @@ -272,12 +275,16 @@ export class ReactView extends DOMWidgetView {
}
}
if(this.model.get("react_version") === 18) {
const root = ReactDOMClient.createRoot(this.el);
root.render(<ErrorBoundary><Component></Component></ErrorBoundary>);
this.root = ReactDOMClient.createRoot(this.el);
this.root.render(<ErrorBoundary><Component></Component></ErrorBoundary>);
} else {
// @ts-ignore
// ReactDOM16.render(<Component></Component>, this.el);

}
}

remove() {
this.root?.unmount();
}
}

0 comments on commit 06305c6

Please sign in to comment.