How to Structure React App using Flux?

  • Cubettech
  • Web App Development
  • 8 years ago
How to Structure React App using Flux?

Why ReactJS?

ReactJs is a Javascript framework, its born on Facebook ad’s organisation. The main purpose of reactJS is to manage complex user interface that change over time.

The concept of reactJS is entirely different from normal web development using MVC because it’s not a general purpose architecture and its actually created to solve the complexity they faced with Facebook. ReactJS never solves all sort of user interface problems, instead it is developed to deal with large set of data that change over time with unidirectional data flow with flux architecture.

How to integrate FLUX Architecture?

Mainly the flux architecture constitutes three components Dispatcher, Store and View. This is not same as Model View Controller. There is no controller in Flux Architecture, instead it uses view-controller concept.
When a user interact with react view, the view propagates an action through Dispatcher to various stores holding the data set and Store will update the View.

Reactjs Flux Structure Architecture


There is only single global Dispatcher. When a user click send, then Dispatcher will generate action and data, but never process it. Action is what we want to do and data is data we need to do it .

        actionName: 'chat',
        data : data 


For our application we need to create store with a collection of logic. A store is not a model but it contains model. A Store is allowed to register Dispatcher callback. The Dispatcher exists to send message from view to store. When Dispatcher dispatches action, Store will perform it. Here, for the action ‘send’.

Var MessageStore= ...




Case ‘chat’ : UserStore.items.push(;





After the action has been executed, the next step is to trigger the change and update view . Dispatcher never triggers the change instead here I use MicroEvent.js which will trigger the change event.


After the store update our View has to re-render. So within our View, we need the following function to update change and there must be componentWillUnmount function to clean eventlistener when component unbinds.

componentDidMount : function(){
componentWillUnmount : function(){
render : function(){
var messages = MessageStore.getAll();
     var messagesHtml = function( listItem ) {
             return <li key={ }>
           { listItem.message }
    return <div>
            { messagesHtml }
<input type=”text” name=”chat”>
        <button onClick={ this.sendMessage }>Send</button>

Learn More From Our Techies

Got a similar project idea?

Connect with us & let’s start the journey!

Questions about our products and services?

We're here to support you.

Staff augmentation is a flexible workforce strategy companies adopt to meet specific project needs or address skill gaps.

Begin your journey!
Need more help?