Skip to content

Commit

Permalink
feat: add React17 support (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Baruch Velez <baruch.velez@wooga.net>
  • Loading branch information
baruchvlz and Baruch Velez committed Nov 17, 2020
1 parent f256c70 commit 465ab5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ export function findReactInstance(element) {
return element._reactRootContainer._internalRoot.current
}

const instanceId = Object.keys(element).find(key => key.startsWith('__reactInternalInstance'))
const instanceId = Object.keys(element).find(
key => key.startsWith('__reactInternalInstance') || key.startsWith('__reactFiber')
)

if (instanceId) {
return element[instanceId]
Expand Down
8 changes: 8 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ describe('utils', () => {
expect(findReactInstance(element)).toBeTruthy()
})

it('should work with React 17', () => {
const element = {
__reactFiber$test1234: true,
}

expect(findReactInstance(element)).toBeTruthy()
})

it('should return undefined if no instance is found', () => {
expect(findReactInstance(document.createElement('div'))).toBeFalsy()
})
Expand Down

0 comments on commit 465ab5e

Please sign in to comment.