i new flux architecture. following facebook's flux todo example. want small modification. wrote small react script data same store rendered on different html tag. when updating data example it's not rendering newly generated script. still displaying old count. wanted ask can use same store different react script? updates made on store 1 script reflected on other script? here snapshot:
the code exact same provided in facebook's github account. adding new component in it. code new component is:
var react = require('react'); var todoactions = require('../actions/todoactions'); var todostore = require('../stores/todostore'); function gettodos() { return { alltodos: todostore.getall() }; } var samplesection = react.createclass({ getinitialstate: function() { return gettodos(); }, componentdidmount: function() { todostore.addchangelistener(this._onchanged); }, componentwillunmount: function() { todostore.removechangelistener(this._onchanged); }, render: function() { var total = object.keys(this.state.alltodos).length; return ( <div> <h1>this sample count: {total}</h1> </div> ); }, _onchanged: function() { this.setstate(gettodos()); } }); module.exports = samplesection;
so want update sample count whenever add new task in todo. suggestion? thank you.
Comments
Post a Comment