You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using `react-dom`'s `findDOMNode()` we get the HTML node generated by a react component instance.
4
+
When using [`react-dom`](https://es.reactjs.org/docs/react-dom.html#finddomnode)'s `findDOMNode()` we get the HTML node generated by a react component instance.
5
5
6
6
`react-dom-instance`'s `findInstance()` goes in the opposite direction: from an HTML node, we get the react component instance that generated it.
7
7
8
-
**Only React v16 and higher is supported**
8
+
**Only React v16 and higher is supported**
9
9
10
10
## How it works
11
11
@@ -50,7 +50,10 @@ Functional components don't have instances, so using `findInstance` with one DOM
50
50
51
51
We can pass some options in order to retrieve the wanted instance from the DOM node:
52
52
53
+
### Options
54
+
53
55
**componentName**
56
+
54
57
Sometimes there are more than one component instance linked to a DOM node. For example, when a component `render` method returns another component, or when using higher order components.
55
58
56
59
In those cases we can use `componentName` to tell `findInstace` what type of component instance we want:
When there are more than one component linked to the same DOM node, `findInstance` navigates recursively through the react fibers looking for the instance of the right component we want. To make this process fast and avoid infinite loops there is a maximum number of iterations that the algorithm does until it decides that the instance can't be found. By default `findInstance` iterates `4` times looking for the instance and return `false` after not finding it.
79
83
80
84
If you have a DOM node with a lot of instances linked and know that more iterations are needed to find the one you want, you can pass `maxIteration` as an option with a bigger number:
This library was thought as a helper for testing with react testing library: sometimes it is useful to access to the component instances in order to create tests.
92
+
This library was thought as a helper for testing with [react testing library](https://github.com/testing-library/react-testing-library): sometimes it is useful to access to the component instances in order to create tests.
89
93
90
94
To make the integration easier, `findInstance` accepts the container returned by react testing library and know how to extract the instance linked to it:
91
95
@@ -112,11 +116,10 @@ it('should say hello', () => {
0 commit comments