Thinking in React
React is, in our opinion, the premier way to build big, fast Web apps with JavaScript. It has scaled very well for us at Facebook and Instagram.
One of the many great parts of React is how it makes you think about apps as you build them. In this document, we’ll walk you through the thought process of building a searchable product data table using React.
Start With A Mock
Imagine that we already have a JSON API and a mock from our designer.
Name | Price |
---|---|
Sporting Goods | |
Football | $49.99 |
Baseball | $9.99 |
Basketball | $29.99 |
Electronics | |
iPod Touch | $99.99 |
iPhone 5 | $399.99 |
Nexus 7 | $199.99 |
- You have your component hierarchy, it’s time to implement your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity.
- To build a static version of your app that renders your data model, you’ll want to build components that reuse other components and pass data using props.
- Props are a way of passing data from parent to child.
- If you’re familiar with the concept of state, don’t use state at all to build this static version.
- There are two types of “model” data in React: props and state.
Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you’re used to, remember that code is read far more than it’s written, and it’s less difficult to read this modular, explicit code.
As you start to build large libraries of components, you’ll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink.