Thinking In React

React isthe premier way to build big, fast Web apps with JavaScript. It has scaled very well on Facebook and Instagram. Experienced React developers typically follow a fixed process when building an application with React.

Step 1: Break The UI Into A Component Hierarchy Step 1: Break The UI Into A Component Hierarchy Step 1: Break The UI Into A Component Hierarchy Try splitting the mockup design into a hierarchy of components. Define your components top-down.

Step 2: Build A Static Version in React Step 2: Build A Static Version in React Step 2: Build A Static Version in React (no state) (no state) (no state) Build a version that takes your data model and renders the UI but has no interactivity.Use props but don't use state at all.React's one-way data flow (also called one-way binding) keeps everything modular and fast.

Step 3: Identify The Minimal But Complete Representation Of UI State Step 3: Identify The Minimal But Complete Representation Of UI State Step 3: Identify The Minimal But Complete Representation Of UI State Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand.

Step 4: Identify Where Your State Should Live Step 4: Identify Where Your State Should Live Step 4: Identify Where Your State Should Live Identify every component that renders something based on that state. Find a common owner component (a single component above all the components that need the state in the hierarchy). Either the common owner or another component higher up in the hierarchy should own the state. If you can't find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common owner component.

Step 5: Add Inverse Data Flow Step 5: Add Inverse Data Flow Step 5: Add Inverse Data Flow

So far, we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state higher up. React makes this data flow explicit to help you understand how your program works, but it does require a little more typing than traditional two-way data binding.