Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an extensible architecture with React

Tags:

My team is creating the administration panel of a CMS using React, Typescript, TSX and Webpack. Each page of the administration panel has been created as a React component, and each page contains many other child components (one for each section).

enter image description here

The CMS distribution currently includes a bundled version of the javascript needed to run the web app, but not the original TSX files.

Now, we would like to make it possible to the developers using our CMS to extend the web app by

1) Injecting additional sections into the UI using a "slot-fill" approach

2) Possibly even overriding the existing sections rendering a different component in the same place.

<div>   <SidebarComponent />   <Section1Component />   <Section2Component />   // How to inject a  possible PluginComponent here? </div> 

From the research we've conducted so far, there seem to be no "official" way to do this, so I'm wondering what would be the best approach in this case.

like image 618
tocqueville Avatar asked Jul 27 '17 16:07

tocqueville


People also ask

What is the best architecture for React?

A good practice while working with your React application architecture is to use reducers to divide your features. The self-contained Redux data with its action creators will let you easily modify or even remove it if you need to, without affecting the architecture.

Is React for spa?

ReactJS is an open source JS library for building UI and used for SPA, and it manages the views of web apps. Reactjs can help you to modify your data without reloading of a page.

Is MVC a React?

React isn't an MVC framework. React is a library for building composable user interfaces. While this is true, the term MVC framework is more of a marketing term. The original MVC concept is closer to a design pattern and has nothing to do with frameworks.


2 Answers

I am facing the same issue where I need a component from a plugin to interact with a component from another plugin with a hook system. I have a created a small codesanbox with the same approach adapted to your need.

Basically the approach is to create a injectedComponents.js at the root of your plugin that specifies in which plugin and area your component needs to be injected.

Here is ademo

like image 172
soupette Avatar answered Oct 14 '22 03:10

soupette


single-spa has some good options in order to achieve this. Please see if it can be help for you.

Microfrontends

Parcels

like image 29
Abhinav Singi Avatar answered Oct 14 '22 03:10

Abhinav Singi