JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://unpkg.com/react@next/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@next/umd/react-dom.development.js"></script>
<div id="container"></div>
Babel + JSX
class App extends React.Component {
constructor(props) {
super(props);
this.state = {list: []};
this.parentNode = document.createElement('div')
document.body.appendChild(this.parentNode)
}
componentDidUpdate() {
console.log('componentDidUpdate');
console.log(this.refs[`item-${this.state.list.length - 1}`].getBoundingClientRect())
}
onClick() {
this.setState({
list: this.state.list.concat([{
number: this.state.list.length
}])
});
}
renderList() {
return this.state.list.map(function(item) {
return (
<div
ref={`item-${item.number}`}
key={item.number}
>
{item.number}
</div>
);
});
}
render() {
return (
<div>
<button onClick={(e) => this.onClick(e)}>add</button>
{ReactDOM.unstable_createPortal(
<div>
{this.renderList()}
</div>,
this.parentNode
)}
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('container'));