diff --git a/.changeset/fifty-bats-stare.md b/.changeset/fifty-bats-stare.md new file mode 100644 index 0000000..25edd77 --- /dev/null +++ b/.changeset/fifty-bats-stare.md @@ -0,0 +1,5 @@ +--- +"single-spa-react": patch +--- + +Automatically support React 17 with default opts. Resolves #202 diff --git a/src/single-spa-react.js b/src/single-spa-react.js index 64a5cd8..c999e82 100644 --- a/src/single-spa-react.js +++ b/src/single-spa-react.js @@ -36,7 +36,6 @@ const defaultOpts = { loadRootComponent: null, // optional opts - renderType: "createRoot", errorBoundary: null, errorBoundaryClass: null, domElementGetter: null, @@ -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`