Closed gilbarbara closed 6 years ago
I've found a way around this but I'm sure if it's the best approach. You need to force a new render after the ref is set in order to use it for the Tooltip.
export default class MyComponent extends React.PureComponent {
setRef = (c) => {
this.target = c;
this.forceUpdate();
};
render() {
return (
<div>
<Target innerRef={this.setRef} />
{this.target && (
<Tooltip
content="My content"
target={this.target}
>
<span>Click me</span>
</Tooltip>
)}
</div>
);
}
}
The problem here is that
ref
is only set after the first parent render, so it doesn't exist when the Tooltip mounts.