From a66d164a374d3fcaa1e9dd2ed834a48a1ce4f5a6 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 23 Nov 2014 12:00:09 -0200 Subject: [PATCH] Adding example about how to disable automatic unmounting of components [ci skip] --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4aed2e79..0ca783e9 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,16 @@ Component = React.createClass
``` -`react_ujs` will also scan DOM elements and call `React.unmountComponentAtNode` on page unload. If you want to disable this behavior, remove `data-react-class` attribute in `componentDidMount`. +`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 MyRootComponent = React.createClass({ + ... + componentDidMount: function() { + this.getDOMNode().parentElement.removeAttribute('data-react-class'); + } +}); +``` To use `react_ujs`, simply `require` it after `react` (and after `turbolinks` if [Turbolinks](https://github.com/rails/turbolinks) is used):