I have a node module (data) that exports an object. This object has properties who's values change.
var data = require('data');
var count = data.count;
data.count is changing it's value (lets pretend it is seconds that are counting).
I use express and handlebars and i currently display the data like this:
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('index', { title: 'Home', data: count });
});
Doing it this way requires the page to be refreshed to see the updated value. My question is: How can I display the value of count in real time without having to refresh the page?
I have been looking into React but I don't really understand how to set it up. I read some tutorials talking about the react module (nom install react) but there is not much documentation on how to use it. I understand the easy guide on the react website but that inserts react script on the client.
If someone can point me in the right direction that would be great.
Thank you.
UPDATE:
So I installed npm insatll react and npm install babel and created a component in react that looks like this (comp.jsx):
var React = require('react/addons');
var data = require('data');
var d = React.createClass({
render: function() {
return (
<h1>{data.votes}</h1>
);
}
});
module.exports.Component = d;
I included this component in my routes file that now looks like this:
require('babel/register');
var React = require('react/addons');
var data = React.createFactory(require('comp.jsx').Component);
router.get('/', function(req, res, next) {
var dataHtml = React.renderToString(data({}));
res.render('index', { reactOutput: data });
});
The data is displayed in my handlebars template like this: {{{reactOutput}}}. The data is shown but still does not update in realtime, the page has to be refreshed to show the change of data.
Any ideas?