Can I fetch the data from the my database in realtime using Rails and ReactJS?
I have just started using React with Rails as this is pretty awesome combination. What I want to know is if there is a way to tell the view to update itself after a component is deleted/ created (so a record is removed/ added to the database)? Something like user after entering the page will subscribe to the database event (?).
What I have now is ComponentContainer with a custom fetch method that gets json from the server. I put it in the componentWillMount and inside a setInterval and run it every single second:
var ComponentsContainer = React.createClass({
componentWillMount() {
this.fetchRecords();
setInterval(this.fetchRecords, 1000);
},
fetchRecords() {
$.getJSON(path_to_results,
(data) => this.setState({components: data});
}, ...render methods etc.
});