Want to persist state across react router transitions? You could do that by using something like Reflux to manage state across your entire application. It would act as your central store and central command library:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | var Reflux = require('reflux'); var actions = Reflux.createActions( ["getAction", "saveAction"] ); var DataStore = Reflux.createStore({ data: data, listenables: [actions], init: function() { this.trigger(this.data); }, onGetAction: function() { // some ajax if you like }, onSaveAction: function() { // more ajax }, getInitialState: function() { return this.data; } }); var App = React.createClass({ mixins: [Reflux.connect(DataStore, 'datastore')], render: function () { var d = this.state.datastore; return ( ... |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.