AEM React hybrid approach | Community
Skip to main content
March 10, 2023

AEM React hybrid approach

  • March 10, 2023
  • 3 replies
  • 1662 views

Hi Folks ,

We are planning to implement hybrid approach in our project architecture where we can use both AEM core components and React SPA at same page. Please let us know if we have any dummy git project available which can be used as reference.

Thanks in advance !

@arunpatidar @Veena_Vikram @nirmal_jose 

Kind Regards,
Kaushik Datta  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

kdattaAuthor
March 15, 2023

Hi @cwalter-1 ,

In this approach we can only use SPA components but not AEM core components in the same container. We need hybrid approach where in normal aem container we will be able to add SPA components as well.

Regards,
Kaushik

Madhur-Madan
Community Advisor
Community Advisor
March 14, 2023
kdattaAuthor
March 15, 2023

Hi @madhur-madan  ,

In this approach we can only use SPA components but not AEM core components in the same container. We need hybrid approach where in normal aem container we will be able to add SPA components as well.

Regards,
Kaushik

mahi1729
August 3, 2023

Do-able with SPA 2.0, but the question is it right to do it that way. And it does come with limitations

1. You can use ReactDOM.render or render method (React v18) to render multiple areas/sections inside your page with React code while the rest can render with HTL as-is

2. Page wise, SPA page and regular Page doesnt have same data types. there is a meta attribute in head section of html that says content type is JSON for SPA pages, so page loadevent, etc are handled differently for SPA Page

3. Now come with some generic HTL code for all sections of page that requires react code, so if you dont have React code deployed inside AEM, then the default HTL will render. And in this HTL code, expose page path, component path, resource type as data attributes data-page-path, data-item-path, data-resource-type and one more attribute for react e.g data-render-src with value as react

4. In your React code, write on dom ready event, scan for all those div tags with render-src value as react, and now based on your components call them using Editablecomponent wrapper passing pagePath itemPath and resourceType props

 

Understand that this approach may not work for container components. Also MapTo statements are optional in this design as we are directly rendering the component. Also since data type of page is not JSON if dialog updates are done, they will not reflect inside react components immediately. So those react based components, be updated with editConfig that will force entire page when dialog is updated should be a workaround we should be able to live with until Adobe offers a real hybrid approach. Hope this info helps !