Skip to content

Commit 5c3fd7c

Browse files
committed
Moves symbol ref into constant.
1 parent e2e64e3 commit 5c3fd7c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/__tests__/index.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ describe('reactTreeWalker', () => {
476476
}
477477

478478
const Bar = React.forwardRef((props, ref) => <Foo ref={ref} {...props} />)
479+
const ref = React.createRef()
479480

480-
const tree = <Bar>foo</Bar>
481+
const tree = <Bar ref={ref}>foo</Bar>
481482

482483
const elements = []
483484
return reactTreeWalker(tree, element => {

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const defaultOptions = {
99
componentWillUnmount: false,
1010
}
1111

12+
const forwardRefSymbol = Symbol.for('react.forward_ref')
13+
1214
// Lifted from https://github.com/sindresorhus/p-reduce
1315
// Thanks @sindresorhus! 🙏
1416
const pReduce = (iterable, reducer, initVal) =>
@@ -75,9 +77,7 @@ const isClassComponent = Comp =>
7577
Comp.prototype.isPureReactComponent)
7678

7779
const isForwardRef = Comp =>
78-
Comp.type &&
79-
Comp.type.$$typeof === Symbol.for('react.forward_ref') &&
80-
typeof Comp.type.render === 'function'
80+
Comp.type && Comp.type.$$typeof === forwardRefSymbol
8181

8282
const providesChildContext = instance => !!instance.getChildContext
8383

0 commit comments

Comments
 (0)