Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created January 1, 2016 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crobinson42/458043e2079bb1799e56 to your computer and use it in GitHub Desktop.
Save crobinson42/458043e2079bb1799e56 to your computer and use it in GitHub Desktop.
React-Bootstrap Modal dynamic mount/dismount from page
/*
Create and attach
*/
var el;
el = document.createElement('div');
el.id = "MyReactModalView";
document.getElementsByTagName('body')[0].appendChild(el);
ReactDOM.render(<MyReactModalView />, document.querySelector('#MyReactModalView'));
/*
Invoke this method to remove from DOM
*/
closeModal() {
ReactDOM.unmountComponentAtNode(document.querySelector('#MyReactModalView'));
},
@crobinson42
Copy link
Author

I get this error in the console when I invoke closeModal()

Warning: React can't find the root component node for data-reactid value `.3.1`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.warning @ bundle.js:70043ReactMount.findComponentRoot @ bundle.js:62568ReactMount.findReactNodeByID @ bundle.js:62535getNode @ bundle.js:62018executeDispatch @ bundle.js:54025executeDispatchesInOrder @ bundle.js:54049executeDispatchesAndRelease @ bundle.js:53492executeDispatchesAndReleaseTopLevel @ bundle.js:53503forEachAccumulated @ bundle.js:67404EventPluginHub.processEventQueue @ bundle.js:53708runEventQueueInBatch @ bundle.js:60987ReactEventEmitterMixin.handleTopLevel @ bundle.js:61003handleTopLevelWithoutPath @ bundle.js:61101handleTopLevelImpl @ bundle.js:61081Mixin.perform @ bundle.js:66886ReactDefaultBatchingStrategy.batchedUpdates @ bundle.js:59718batchedUpdates @ bundle.js:64962ReactEventListener.dispatchEvent @ bundle.js:61212
bundle.js:62571 Uncaught TypeError: Cannot read property 'firstChild' of undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment