react-overlays
react-overlays copied to clipboard
Referenced component after one Portal?
Hi, I have an issue with Portal, in some cases the container parameter used by the Portal component is one function with a reference which may be undefined. It's undefined if the referenced component is declared after a Portal.
You can see here the problem: https://github.com/julien-f/issue-react-overlays-portal/blob/master/src/index.js
To build this example, clone the repo and use npm install && npm run build.
See the results in src/index.html.
I fixed the problem with this code:
componentDidMount () {
this.forceUpdate()
}
But it's not a proper solution I think. Any ideas to fix this? Thx.
I'm not sure there is anything we can do to fix this, without waiting a tick to get the container, which doesn't work for other reasons.
@jquense IMHO it should at least be documented that the only reason your example works is because the portal is used after the first rendering.
And maybe you should document a usable hack such as using this.forceUpdate() in componentWillMount() and recreating a container function (to trigger a rerender of the Portal).
yeah there should be something. thinking a bit more on it there may actually be a way to handle it at least sloppily. I'm not sure it's a good idea, but when I get a moment I can explore it. Also happy to take PR's
We'd be glad to get a PR to the docs here.