markusspiske / Pixabay
Whether you’re diving into React.js for the first time or simply looking for a better way to manage your React.js projects, here are some tips and best practices to keep in mind as you bring your next project to life.
1. Learn the Flux Design Pattern
- Stores are similar to the models in MVC, except they manage the application state for a particular domain within the application.
- The Dispatcher is a simple single registry of callbacks to the stores within the application. It also manages the dependencies between stores.
- Views are the same as the view in MVC, except in the context of React and Flux, also include Controller-Views, which listen for change events and retrieve application state from stores as required.
Basically, all data in the application flows through the dispatcher, which acts as a central hub. This data is tracked as Actions, which are provided to the dispatcher in an action creator method, often as a result of a user interacting with the view. The dispatcher invokes the registered callback, effectively dispatching the action to all stores that have registered with that callback. The stores in turn relay that change event to the controller-views to alert them of the change. The controller-views listen for events, retrieve data from the appropriate stores as required and re-render themselves and all their children in the component tree accordingly.
2. Get Used to Immutable States
3. Use Functional Components as Much as Possible
Source:: Business 2 Community