Answer the question
In order to leave comments, you need to log in
Is it possible to dynamically load components in ReactJS without knowing about them when building the application itself (as it is implemented in Angular 2+)?
Hello everyone, please help me solve the problem, although help in the search.
There is a task:
* developers develop components (assume on react)
* then they put the compiled component in the dist directory
* indicate in the database that there is such and such a component
* after that, when the application is initialized in the browser
* asks the server which components it displays and loads asynchronously anything-1.component.js, .. N
* and easily renders all components and binds data
I myself did not write anything in React (only helloWorld wrote once), I write mainly in Angular
But after the first ng, I realized that they overdid it. In order to dynamically load components there, so that a component factory with its templates is created, you need to specify entryComponents for the root module, but here the problem is that you need to specify all the components that you want to dynamically display, and if I'm in the browser I don’t know which ones, it turns out I specify (all my 10 thousand components for entryComponents as links), well, this is a stupid decision, besides, if I develop a new component, I will have to rebuild my application (via webpack or something) .
What does not suit me is that I have to specify all the components that I have, and this is implemented in Angular, Carl ... The first Angular was written in pure javascript, but everything is global there, at any time, I could load my script asynchronously (which would be an Angular controller with templates) and it all worked for me if I connected a new controller to angular.module, and now it’s like this only when building.
@NgModule({
imports: [...],
declarations: [...],
entryComponents: [
Anything1Component,
...,
AnythingNComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question