( container: Element | Document | DocumentFragment, options?: CreateRootOptions, )
| 169 | }; |
| 170 | |
| 171 | export function createRoot( |
| 172 | container: Element | Document | DocumentFragment, |
| 173 | options?: CreateRootOptions, |
| 174 | ): RootType { |
| 175 | if (!isValidContainer(container)) { |
| 176 | throw new Error('Target container is not a DOM element.'); |
| 177 | } |
| 178 | |
| 179 | warnIfReactDOMContainerInDEV(container); |
| 180 | |
| 181 | const concurrentUpdatesByDefaultOverride = false; |
| 182 | let isStrictMode = false; |
| 183 | let identifierPrefix = ''; |
| 184 | let onUncaughtError = defaultOnUncaughtError; |
| 185 | let onCaughtError = defaultOnCaughtError; |
| 186 | let onRecoverableError = defaultOnRecoverableError; |
| 187 | let onDefaultTransitionIndicator = defaultOnDefaultTransitionIndicator; |
| 188 | let transitionCallbacks = null; |
| 189 | |
| 190 | if (options !== null && options !== undefined) { |
| 191 | if (__DEV__) { |
| 192 | if ((options: any).hydrate) { |
| 193 | console.warn( |
| 194 | 'hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, <App />) instead.', |
| 195 | ); |
| 196 | } else { |
| 197 | if ( |
| 198 | typeof options === 'object' && |
| 199 | options !== null && |
| 200 | (options: any).$$typeof === REACT_ELEMENT_TYPE |
| 201 | ) { |
| 202 | console.error( |
| 203 | 'You passed a JSX element to createRoot. You probably meant to ' + |
| 204 | 'call root.render instead. ' + |
| 205 | 'Example usage:\n\n' + |
| 206 | ' let root = createRoot(domContainer);\n' + |
| 207 | ' root.render(<App />);', |
| 208 | ); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | if (options.unstable_strictMode === true) { |
| 213 | isStrictMode = true; |
| 214 | } |
| 215 | if (options.identifierPrefix !== undefined) { |
| 216 | identifierPrefix = options.identifierPrefix; |
| 217 | } |
| 218 | if (options.onUncaughtError !== undefined) { |
| 219 | onUncaughtError = options.onUncaughtError; |
| 220 | } |
| 221 | if (options.onCaughtError !== undefined) { |
| 222 | onCaughtError = options.onCaughtError; |
| 223 | } |
| 224 | if (options.onRecoverableError !== undefined) { |
| 225 | onRecoverableError = options.onRecoverableError; |
| 226 | } |
| 227 | if (enableDefaultTransitionIndicator) { |
| 228 | if (options.onDefaultTransitionIndicator !== undefined) { |
no test coverage detected