Skip to content

Adding example about how to disabling automatic unmounting component #121

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

Closed
wants to merge 1 commit into from
Closed

Conversation

andreynering
Copy link
Contributor

Adding an example for who don't want components being unmounted.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

`react_ujs` will also scan DOM elements and call `React.unmountComponentAtNode` on page unload. If you want to disable this behavior (if you are not using Turbolinks), remove `data-react-class` attribute in `componentDidMount`:

```js
var MyComponent = React.createClass({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this hack as a whole but while it exists let's make the example even clearer. Can we call it MyRootComponent or something similar so it's clear that this doesn't work for components at arbitrary depth. There's a danger there as in theory a component shouldn't know if it's the top-most since you could render the same component as a child elsewhere. But I suppose that's probably not what most people are doing so let's just make it as clear as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zpao Good point. Done!

@dapi
Copy link

dapi commented Mar 6, 2015

Thanks for a tip )

@rmosolgo
Copy link
Member

For non-Turbolinks settings, this has been disabled by default (since #318)

@rmosolgo rmosolgo closed this Nov 24, 2015
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

Successfully merging this pull request may close these issues.

5 participants