Skip to content

Commit

Permalink
Change default renderType based on React version. Resolves #202 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning authored Jan 5, 2024
1 parent 57f8455 commit ec968f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-bats-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"single-spa-react": patch
---

Automatically support React 17 with default opts. Resolves #202
10 changes: 9 additions & 1 deletion src/single-spa-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const defaultOpts = {
loadRootComponent: null,

// optional opts
renderType: "createRoot",
errorBoundary: null,
errorBoundaryClass: null,
domElementGetter: null,
Expand Down Expand Up @@ -68,6 +67,15 @@ function singleSpaReact(userOpts) {
);
}

if (!opts.renderType) {
// https://github.com/single-spa/single-spa-react/issues/202
if (opts.ReactDOMClient?.createRoot) {
opts.renderType = "createRoot";
} else {
opts.renderType = "render";
}
}

if (!opts.rootComponent && !opts.loadRootComponent) {
throw new Error(
`single-spa-react must be passed opts.rootComponent or opts.loadRootComponent`
Expand Down

0 comments on commit ec968f2

Please sign in to comment.