Answer the question
In order to leave comments, you need to log in
How to pass data to a multipage react application?
Good day!
I'm trying to understand react.js and the question arose - how to transfer data to the react application correctly? I am interested in the information that is displayed on all pages of the site. Let's say the menu is in the Header. Is it possible to make this data be passed as a variable with json in the head? Something like this:
<head>
<script>
var menu = {
"items": [
{
"title": "Главная",
"url": "/"
},
{
"title": "Каталог",
"url": "/catalog/"
},
]
}
</script>
<script src="react.js"></script>
<script src="main.js"></script>
</head>
<body>
<div id="app"></div>
</body>
Answer the question
In order to leave comments, you need to log in
Yes, you can do this, but it's better something like this:
During initialization, this data can be intercepted into the state of the root component, or the library's state management repository if it is used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question