Skip to content
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

Bug: #19844

Closed
Ramsy12 opened this issue Sep 16, 2020 · 1 comment
Closed

Bug: #19844

Ramsy12 opened this issue Sep 16, 2020 · 1 comment

Comments

@Ramsy12
Copy link

Ramsy12 commented Sep 16, 2020

I have used one react component, in another one, via Dependency-injection. This causes the Hook to not work, because there are 2 React instances loaded. What can I do?

React version:
"react": "^16.13.1",
"react-dom": "^16.13.1",

Steps To Reproduce

  1. Write 2 Components as Libraries. Once exports a MountApp-function, and the other a GetInstance-funciton.
  2. In the main html include both libraries and write something like:
	<script type="text/javascript">
		(function () {
			App2.MountApp({
				rootElement: document.getElementById("IrrigationReportPerField"),
				dependency: App2  // Here it is the dependency injection.
			});
	</script>
  1. In the App2 you have something like this:
import React, { useState } from 'react';

function App() {
	const [lala, setLala] = useState({});    // Here it fails!
	return <div>{whatever}</div>;
}

export default App;

import React from 'react';
import App from './App';

function GetInstance() {
return (
		<React.StrictMode>
			<App />
		</React.StrictMode>
	);
}
  1. In the App1 you have
import React from 'react';

function App({ App2}) {
	const myTableContainer = App2.GetInstance();

	return <div>{myTableContainer}</div>;
}

export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

function MountApp({ rootElement, App2}) {
	ReactDOM.render(
		<React.StrictMode>
			<App App2={App2} />
		</React.StrictMode>,
		rootElement
	);
}

export { MountApp };

The current behavior

Error sending me to https://reactjs.org/docs/error-decoder.html/?invariant=321 - which is correct. There are two instances loaded.

The expected behavior

I would like a way to use one App from the other, just like any external package.

@Ramsy12 Ramsy12 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 16, 2020
@eps1lon
Copy link
Collaborator

eps1lon commented Sep 16, 2020

You can check out #13991 to explore possible solutions.

@eps1lon eps1lon closed this as completed Sep 16, 2020
@eps1lon eps1lon added Resolution: Duplicate and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants