The key here is to pass variables over 'drupalSettings' => ['myData' => $some_value], where you can then pass whatever you need to decoupled app(react)
class ReactListBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$build['react_list_block'] = [
'#markup' => '<div id="list-app"></div>',
'#attached' => [
'library' => 'ww_react_list/react-list',
'drupalSettings' => ['myData' => $some_value],
],
];
return $build;
}
}
and this will then be readable in your app.js as console.log(drupalSettings);
Other way you can pass variables to your react app is to attach them to page as page attachments, this would look like below
function my_decoupled_page_attachments(array &$attachments) {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$attachments['#attached']['drupalSettings']['decoupled']['language'] = $language;
}
and you would have then this variables in your app that you can try and read with console.log(drupalSettings);