I'm rendering a page on get and passing a json object with it, like so:
/* GET home page. */
router.get('/', (req, res, next) => {
const message = req.session.message;
res.render('index', { data: message });
});
This is my index.ejs view:
<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<div id='react-app'> Loading …</div>
</body>
<script src="/javascripts/build.js"></script>
</html>
The page that's being rendered is index.js:
import React from 'react';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { render } from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import './css/msha.scss';
import Store from './store';
import TemplateContainer from './components/TemplateContainer';
const renderApp = (Component) => {
render(
<AppContainer>
<Provider store={Store}>
<Component />
</Provider>
</AppContainer>,
document.querySelector('#react-app'),
);
};
renderApp(TemplateContainer);
if (module && module.hot) {
module.hot.accept('./components/TemplateContainer', () => {
renderApp(TemplateContainer);
});
}
The page being rendered contains a react component. How do I access this data inside the react component?
indexview code.