Skip to content

Commit 5cf61c9

Browse files
authored
Fix forwardRef component nested with a memo HOC (#15)
* Fix forwardRef component nested in memo HOC In the case of: memo(forwardRef(SomeComponent)) The memo component would be correctly detected but would assume that it may only contain a class or function component and render it. Instead of rendering the nested component, this fix returns a proper element from the memo component visitor. * Update visitor test for memo components
1 parent 6e69818 commit 5cf61c9

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/__tests__/visitor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('visitElement', () => {
215215
})
216216

217217
it('walks over memo components', () => {
218-
const Test = React.memo(() => <Noop />)
218+
const Test = React.memo(Noop)
219219
const children = visitElement(<Test />, [], () => {})
220220
expect(children.length).toBe(1)
221221
expect(children[0].type).toBe(Noop)

src/visitor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ export const visitElement = (
134134
case REACT_MEMO_TYPE: {
135135
const memoElement = ((element: any): MemoElement)
136136
const type = memoElement.type.type
137-
const fauxElement = (createElement((type: any), memoElement.props): any)
138-
const child = render(type, memoElement.props, queue, visitor, fauxElement)
137+
const child = createElement((type: any), memoElement.props)
139138
return getChildrenArray(child)
140139
}
141140

0 commit comments

Comments
 (0)