Skip to content

Clarify portals docs #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gaearon opened this issue Apr 25, 2018 · 2 comments
Open

Clarify portals docs #840

gaearon opened this issue Apr 25, 2018 · 2 comments

Comments

@gaearon
Copy link
Member

gaearon commented Apr 25, 2018

https://reactjs.org/docs/portals.html

We should make it clearer in the first paragraph it’s not imperative and doesn’t “work” outside of render. There is a common confusion that this should be called in lifecycles (where it has no effect).

@danburzo
Copy link
Contributor

(Moved from #911) — I think we should also include a mention of whether the Portal will take control of the DOM element it receives as container (and, consequently, it needs its own DOM element to render into), similarly to how it's noted for ReactDOM.render(). Clarifying this this can help people avoid creating useless DOM nodes "just in case" — that is, if there aren't any caveats to using, for example, document.body as a target.

Another thing I was momentarily surprised by — although it makes perfect sense — is that if you rely on CSS classes to style an element that you then transport to a different part of the the DOM, it will not inherit styles from its parent React element. Maybe warrants a tiny note?

@rickhanlonii
Copy link
Member

@gaearon can we close this? I think you explained this well in the new docs https://react.dev/reference/react-dom/createPortal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants