From fffc5e8511b048fc6fcafeb48ac11ccb12bf0cd2 Mon Sep 17 00:00:00 2001 From: Edmond Chui Date: Wed, 29 Apr 2020 16:08:34 -0600 Subject: [PATCH] Update index.js --- react_ujs/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/react_ujs/index.js b/react_ujs/index.js index 0ef70a5a3..84e9665ea 100644 --- a/react_ujs/index.js +++ b/react_ujs/index.js @@ -73,6 +73,11 @@ var ReactRailsUJS = { useContext: function(requireContext) { this.getConstructor = constructorFromRequireContextWithGlobalFallback(requireContext) }, + + // Called after React unmounts component at `node` + // Override this function to perform any cleanup + // the default function does nothing + onComponentUnmountAtNode: function (node) {}, // Render `componentName` with `props` to a string, // using the specified `renderFunction` from `react-dom/server`. @@ -135,6 +140,7 @@ var ReactRailsUJS = { for (var i = 0; i < nodes.length; ++i) { var node = nodes[i]; ReactDOM.unmountComponentAtNode(node); + ReactRailsUJS.onComponentUnmountAtNode(node); } },