Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit a147158

Browse files
authored
Merge pull request #51 from bradleyayers/patch-1
Add documentation about `ref` behaviour.
2 parents 2ab63ce + 7815a23 commit a147158

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ When you pass down props to the web component, instead of setting attributes lik
7272

7373
If your web component renders content to itself, make sure you're using Shadow DOM and that you render it to the shadow root. If you do this `children` and props get passed down as normal and React won't see your content in the shadow root.
7474

75+
### `ref`
76+
77+
If you need access the the underlying DOM element, you can use the standard [`ref` API](https://facebook.github.io/react/docs/more-about-refs.html). Be aware though that since you're dealing with a React Component, you'll need to use [`ReactDOM.findDOMNode`](https://facebook.github.io/react/docs/top-level-api.html#reactdom.finddomnode):
78+
79+
```js
80+
import ReactDOM from 'react-dom';
81+
const ReactComponent = reactify(class WebComponent extends HTMLElement {});
82+
83+
class MyComponent extends Component {
84+
constructor() {
85+
super();
86+
this.webComponent = null;
87+
}
88+
89+
render() {
90+
return (
91+
<ReactComponent
92+
ref={reactComponent => {
93+
this.webComponent = ReactDOM.findDOMNode(reactComponent);
94+
}
95+
/>
96+
);
97+
}
98+
}
99+
```
100+
75101
### Injecting React and ReactDOM
76102
77103
By default, the React integration will look for `React` and `ReactDOM` on the window. However, this isn't the case for all apps. If you're using ES2015 modules or CommonJS, you'll have to inject them into the reactify function as options:

0 commit comments

Comments
 (0)