Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make createRoot / hydrateRoot compatible with React spec #3560

Merged
merged 1 commit into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}