I am refacoring a component to React code.
Previously I was compiling it with Jade and passing the i18n text from a Jade global directly to the HTML. Something like this:
// in Node.js / Express
const text = require('./assets/texts.json');
app.get('/route', (req, res) => {
render('page', text);
});
and in Jade I would have:
h3= text.en.title
p= text.en.subtitle
Now I am doing this with React and I wonder how to pass data into it?
If I do const text = require('./texts.json'); inside the react file I get a error...
How to pass data from Node to React in the same way as I did with Jade? Is it only possible via Ajax on the client side already?
json-loadergithub.com/webpack/json-loader, but maybe your question is more about express?data-textattribute with a json string in the element where react is going to mount... but wonder if there is another more clean way.