0

I'm going to use React with D8 and perform so-called Progressive decoupling, i.e. use React Components on existing Drupal pages.

There are several articles on this topic but the information is not complete. It would be great to summarize it and define the best method of implementing React.

I've chosen this guide to start with and created a React App inside my custom module folder. I've also decided to use JSON API instead of RESTful Services, according to the recommendations.

After that author recommends to use Paragraph module to implement separate paragraphs which will be replaced by React components.

It is not clear to me what structure should my custom module have? Do I need a router, controller, .module file or maybe a plugin? Where should I put hook_preprocess_paragraph__HOOK function?

My idea is simple - to use different paragraphs for different React components and insert them into an existing layout.

Any best practices?

1

The 'React block' module aims to add some more structure around React components and Redux state management in Drupal.

React blocks are defined by adding a simple YML file to your exising React component. This allows front end devlopers to create and manage React components as they normally would, and by including this YML file they can make the component available inside Drupal.

-1

You can use https://drupalconsole.com/home which can generate module files for you. What you need for this example is an info and a module file which can be created using the drupal gm command from Drupal console. This guide https://www.drupal.org/docs/8/creating-custom-modules is also a good start to understand the structure of modules.
Also, you'll need to define libraries for your module as per this guide https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module

2
  • Thank you, Ismail! I didn't need a router and controller, a simple generated module was just fine. Sep 19 '18 at 7:53
  • Please try PDB @MaxZviagintsev
    – Kalidasan
    Jan 16 '19 at 12:36
-1

React is just js. You can simply embed react.js and your react app js into your template.

Please look at the section React app embedded in Drupal for basic information on this setup and caveats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.