Avoid including the React library on each React component In way to do that, we have a few challenges to solve:ġ. I'm not interested in having a single React page or having a full headless solution, I just want to have the possibility to solve the complexity of some page components with React, let's call it a hybrid approach that is represented in the below picture: Simple scenarios to use React inside Drupalįor this article, I'm just concerned about having one or more React components rendered in a Drupal page. If we look at a post from the Drupal creator, we can see that some work is already in progress by the Drupal community, mostly on adopting React to rebuild the administrative UIs of Drupal (in a similar way on what Wordpress did with amazing project Calypso) and on providing the ability to be agnostic in the frontend and support multiple Javascript libraries (e.g. Please check this project and we can see what amazing work can be built, imagine something like that powering the Drupal admin interface. So why not forget it and make use of a modern library that is component based and provide us all modern mechanisms to build rich user experiences. The combination of Twig templates with jQuery is not good enough when the complexity increases, and often, we end with dozens of tweaks that are not good for the performance and code manageability. I believe that one of the fundamental strengths of Drupal is the flexibility on modeling and storing structures of contents, and one of the weaknesses is on the way we consume and display those structures to the end user, mostly when the required user interactions are complex. I will not go along with all details about React as is not the purpose of this article, and you can find them on the official website. It sounds quite simple, but in fact is a bit more elaborated, in the end, React is Javascript library to build user interfaces, that approaches a concept of reusable components and solve a historical issue with the slowness of the DOM by replacing it with a Virtual DOM structure. In this post, I'll provide a different approach by experimenting the React library in Drupal as a full replacement for the Twig layer.įirst of all, and to avoid a common myth, React is not a Javascript Framework, but "merely" a view library that provides a few function hooks to render HTML. In a previous post I introduced Cockpit CMS combined with React as a solution for implementing simple websites.
0 Comments
Leave a Reply. |