Skip to content

Commit

Permalink
make createRoot / hydrateRoot compatible with React spec (#3560)
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa authored Jun 12, 2022
1 parent 1dc4f56 commit 2834d5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 11 additions & 5 deletions compat/client.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const { render, hydrate } = require('preact/compat');
const { render, hydrate, unmountComponentAtNode } = require('preact/compat');

exports.createRoot = function(container) {
function createRoot(container) {
return {
render(children) {
return render(children, container);
render(children, container);
},
unmount() {
unmountComponentAtNode(container);
}
};
};
}

exports.createRoot = createRoot;

exports.hydrateRoot = function(container, children) {
return hydrate(children, container);
hydrate(children, container);
return createRoot(container);
};
10 changes: 7 additions & 3 deletions compat/client.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { render, hydrate } from 'preact/compat'
import { render, hydrate, unmountComponentAtNode } from 'preact/compat'

export function createRoot(container) {
return {
render(children) {
return render(children, container)
render(children, container)
},
unmount() {
unmountComponentAtNode(container)
}
}
}

export function hydrateRoot(container, children) {
return hydrate(children, container);
hydrate(children, container)
return createRoot(container)
}

0 comments on commit 2834d5a

Please sign in to comment.