Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
Multiple instances, multiples stores with React Redux

I have a small application project under ReactJs, and after studying the question, I decided to use a different store for each instance created.

In fact, this way I can instantiate multiple components on the same page as follows:

var instance1 = new MyApp(".class1");
var instance2 = new MyApp(".class2");

And the MyApp class looks like this:

class MyApp {

    constructor(myClass){
        this.myClass = myClass;
        this.context= createContext("myClass");
        this.init();
    }
    
    init(){
        render(
            <Provider  context={this.context} store={createStore(this.myClass)}>
                <App />
            </Provider>,
            document.querySelector(this.myClass)
        );
    }

    destroy(){
        render(null, document.querySelector(this.myClass));
    }

}

Everything works correctly! The only concern I encounter is how to proceed to retrieve the store of each instance from a class/function helper.

Let's say I create a Helper class like this:

class Helper {
    constructor(myClass){
        this.myClass = myClass;
    }

    getStore(){
        // I have a function that allows me to find the corresponding store using the class of the instance
        return retrieveStore(this.myClass);
    }
}
export default Helper;

And that I declare an attribute in the constructor of the MyApp class like this, having taken care to import it of course:

constructor(myClass){
this.myClass = myClass;
this.context = createContext("myClass");
this.helper = new Helper("myClass"); // <-- Here
this.init();

}

If I do this:

var instance = new MyApp(".class1");
instance.helper.getStore();

I get the store corresponding to the instance.

So my question is, how to get the helper class instance corresponding to the current MyApp instance inside a React component? Because I can't import the class, since I will only initialize a new class and I won't have the store corresponding to the current MyApp instance.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda