Skip to content

Commit 61cc8ae

Browse files
committed
null outside of dev
1 parent 4bf159b commit 61cc8ae

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

src/content/reference/react/captureOwnerStack.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ Experimental versions of React may contain bugs. Don't use them in production.
1616

1717
<Intro>
1818

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.
2120

2221
```js
2322
captureOwnerStack();
@@ -52,25 +51,10 @@ function Component() {
5251

5352
#### Returns {/*returns*/}
5453

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`.
6855

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.
7458

7559
## Owner Component stacks vs parent Component stacks {/*owner-component-stacks-vs-parent-component-stacks*/}
7660

@@ -156,7 +140,7 @@ In addition to the stack trace of the <CodeStep step={1}>error</CodeStep> itself
156140
This can help trace the error especially when the error is caused by props. The owner Component stack helps trace the flow of props.
157141

158142
```jsx [[9, 15, "error"], [34, 10, "captureOwnerStack"]]
159-
import * as React from 'react'
143+
import { captureOwnerStack } from 'react'
160144
import { hydrateRoot } from 'react-dom/client';
161145

162146
const root = hydrateRoot(
@@ -165,7 +149,7 @@ const root = hydrateRoot(
165149
{
166150
onCaughtError: (error, errorInfo) => {
167151
if (process.env.NODE_ENV !== 'production') {
168-
const ownerStack = React.captureOwnerStack();
152+
const ownerStack = captureOwnerStack();
169153
error.stack += ownerStack;
170154
}
171155
console.error(

0 commit comments

Comments
 (0)