Reflux - Creating Your First Action in React

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet

Reflux uses Actions to tell the Stores when to update. We will wire Actions and Stores together to create a simple updatable age field React component.

hipertracker
hipertracker
~ 6 years ago

In general, stores can be used in many components. And the component can subscribe to many stores. It means, stores should know NOTHING about subscribed components states. So I would rather write something like:

var store = Reflux.createStore({
    listenables: [actions],
    onUpdateAge() {
        person.age = Math.random() * 100;
        this.trigger({person});
    }
});

var App = React.createClass({
    mixins: [Reflux.connect(store, 'updatePerson')],
    updatePerson(person) {
      this.setState({person})
    }
    //...
})