You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/client/createRoot.md
+41-46Lines changed: 41 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -348,25 +348,24 @@ It is uncommon to call `render` multiple times. Usually, your components will [u
348
348
349
349
By default, React will log all uncaught errors to the console. To implement your own error reporting, you can provide the optional `onUncaughtError` root option:
The <CodeStep step={1}>onUncaughtError</CodeStep> option is a function called with two arguments:
@@ -612,25 +611,24 @@ export default function App() {
612
611
613
612
By default, React will log all errors caught by an Error Boundary to `console.error`. To override this behavior, you can provide the optional `onCaughtError` root option to handle errors caught by an [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary):
// captureOwnerStack is only available in react@canary.
617
-
import { captureOwnerStack } from'react';
618
-
import { createRoot } from'react-dom/client';
616
+
import {captureOwnerStack} from'react';
617
+
import { createRoot } from"react-dom/client";
618
+
import {reportCaughtError} from"./reportError";
619
619
620
-
constroot=createRoot(
621
-
document.getElementById('root'),
622
-
{
623
-
onCaughtError: (error, errorInfo) => {
624
-
console.error(
625
-
'Caught error',
626
-
error,
627
-
errorInfo.componentStack,
620
+
constcontainer=document.getElementById("root");
621
+
constroot=createRoot(container, {
622
+
onCaughtError: (error, errorInfo) => {
623
+
if (error.message!=='Known error') {
624
+
reportCaughtError({
625
+
error,
626
+
componentStack:errorInfo.componentStack,
628
627
ownerStack:captureOwnerStack()
629
-
);
628
+
});
630
629
}
631
630
}
632
-
);
633
-
root.render(<App />);
631
+
});
634
632
```
635
633
636
634
The <CodeStep step={1}>onCaughtError</CodeStep> option is a function called with two arguments:
@@ -903,26 +901,23 @@ function Throw({error}) {
903
901
904
902
React may automatically render a component a second time to attempt to recover from an error thrown in render. If successful, React will log a recoverable error to the console to notify the developer. To override this behavior, you can provide the optional `onRecoverableError` root option:
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/client/hydrateRoot.md
+42-44Lines changed: 42 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -378,25 +378,25 @@ It is uncommon to call [`root.render`](#root-render) on a hydrated root. Usually
378
378
379
379
By default, React will log all uncaught errors to the console. To implement your own error reporting, you can provide the optional `onUncaughtError` root option:
// captureOwnerStack is only available in react@canary.
383
383
import { captureOwnerStack } from'react';
384
-
import { hydrateRoot } from'react-dom/client';
384
+
import { hydrateRoot } from"react-dom/client";
385
+
importAppfrom"./App";
386
+
import {reportUncaughtError} from"./reportError";
385
387
386
-
hydrateRoot(
387
-
document.getElementById('root'),
388
-
<App />,
389
-
{
390
-
onUncaughtError: (error, errorInfo) => {
391
-
console.error(
392
-
'Uncaught error',
388
+
constcontainer=document.getElementById("root");
389
+
hydrateRoot(container, <App />, {
390
+
onUncaughtError: (error, errorInfo) => {
391
+
if (error.message!=='Known error') {
392
+
reportUncaughtError({
393
393
error,
394
-
errorInfo.componentStack,
395
-
captureOwnerStack()
396
-
);
394
+
componentStack:errorInfo.componentStack,
395
+
ownerStack:captureOwnerStack()
396
+
});
397
397
}
398
398
}
399
-
);
399
+
});
400
400
```
401
401
402
402
The <CodeStep step={1}>onUncaughtError</CodeStep> option is a function called with two arguments:
@@ -579,7 +579,7 @@ export function reportRecoverableError({error, cause, componentStack, ownerStack
579
579
// captureOwnerStack is only available in react@canary.
580
580
import { captureOwnerStack } from'react';
581
581
import { hydrateRoot } from"react-dom/client";
582
-
importAppfrom"./App.js";
582
+
importAppfrom"./App";
583
583
import {reportUncaughtError} from"./reportError";
584
584
import"./styles.css";
585
585
import {renderToString} from'react-dom/server';
@@ -645,25 +645,25 @@ export default function App() {
645
645
646
646
By default, React will log all errors caught by an Error Boundary to `console.error`. To override this behavior, you can provide the optional `onCaughtError` root option for errors caught by an [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary):
// captureOwnerStack is only available in react@canary.
650
-
import { captureOwnerStack } from'react';
651
-
import { hydrateRoot } from'react-dom/client';
650
+
import {captureOwnerStack} from'react';
651
+
import { hydrateRoot } from"react-dom/client";
652
+
importAppfrom"./App.js";
653
+
import {reportCaughtError} from"./reportError";
652
654
653
-
hydrateRoot(
654
-
document.getElementById('root'),
655
-
<App />,
656
-
{
657
-
onCaughtError: (error, errorInfo) => {
658
-
console.error(
659
-
'Caught error',
655
+
constcontainer=document.getElementById("root");
656
+
hydrateRoot(container, <App />, {
657
+
onCaughtError: (error, errorInfo) => {
658
+
if (error.message!=='Known error') {
659
+
reportCaughtError({
660
660
error,
661
-
errorInfo.componentStack,
661
+
componentStack:errorInfo.componentStack,
662
662
ownerStack:captureOwnerStack()
663
-
);
663
+
});
664
664
}
665
665
}
666
-
);
666
+
});
667
667
```
668
668
669
669
The <CodeStep step={1}>onCaughtError</CodeStep> option is a function called with two arguments:
@@ -938,26 +938,24 @@ function Throw({error}) {
938
938
939
939
When React encounters a hydration mismatch, it will automatically attempt to recover by rendering on the client. By default, React will log hydration mismatch errors to `console.error`. To override this behavior, you can provide the optional `onRecoverableError` root option:
0 commit comments