@@ -16,8 +16,7 @@ Experimental versions of React may contain bugs. Don't use them in production.
16
16
17
17
<Intro >
18
18
19
- ` captureOwnerStack ` reads the current ** owner** Component stack and returns it as a string.
20
- If no owner stack is available, it returns an empty string.
19
+ ` captureOwnerStack ` reads the current ** owner** Component stack and returns it as a string if available.
21
20
22
21
``` js
23
22
captureOwnerStack ();
@@ -52,25 +51,10 @@ function Component() {
52
51
53
52
#### Returns {/* returns* /}
54
53
55
- ` captureOwnerStack ` returns ` string ` .
56
-
57
- #### Caveats {/* caveats* /}
58
-
59
- ` captureOwnerStack ` is only available in development builds of React.
60
- In production builds, the ` captureOwnerStack ` export does not exist.
61
-
62
- Only call ` captureOwnerStack ` in development environments:
63
-
64
- ``` tsx
65
- // Use a namespace import to avoid errors in production when using ES modules.
66
- // Non-existing exports throw a `SyntaxError` in ES modules.
67
- import * as React from ' react' ;
54
+ ` captureOwnerStack ` returns ` string | null ` .
68
55
69
- let ownerStack = ' ' ;
70
- if (process .env .NODE_ENV !== ' prodction' ) {
71
- ownerStack = React .captureOwnerStack ();
72
- }
73
- ```
56
+ If no owner stack is available, it returns an empty string.
57
+ Outside of development builds, ` null ` is returned.
74
58
75
59
## Owner Component stacks vs parent Component stacks {/* owner-component-stacks-vs-parent-component-stacks* /}
76
60
@@ -156,7 +140,7 @@ In addition to the stack trace of the <CodeStep step={1}>error</CodeStep> itself
156
140
This can help trace the error especially when the error is caused by props. The owner Component stack helps trace the flow of props.
157
141
158
142
``` jsx [[9, 15, "error"], [34, 10, "captureOwnerStack"]]
159
- import * as React from ' react'
143
+ import { captureOwnerStack } from ' react'
160
144
import { hydrateRoot } from ' react-dom/client' ;
161
145
162
146
const root = hydrateRoot (
@@ -165,7 +149,7 @@ const root = hydrateRoot(
165
149
{
166
150
onCaughtError : (error , errorInfo ) => {
167
151
if (process .env .NODE_ENV !== ' production' ) {
168
- const ownerStack = React . captureOwnerStack ();
152
+ const ownerStack = captureOwnerStack ();
169
153
error .stack += ownerStack;
170
154
}
171
155
console .error (
0 commit comments