While you may already know of React, since it’s been a bit of a buzzword in the dev community lately, you might be wondering if you should take the time to learn it. So today, I’m going to give you some background on React and a couple reasons why you should consider adding it to your skill set.
Rethinking Best Practices
But the team behind React thought they had a better idea. Instead of completely separating the application logic from the view, it coupled the logic and view into one file using something called the component-based architecture, which allowed the composition of these components.
The programming community was initially a bit confused by this approach and didn’t seem to take to it. Now fast-forward to today: Both Ember and Angular, as well as some newer frameworks and view libraries, have moved toward a component-based architecture — even coupling some of the logic and the view code in the same file like React.
Don’t Mutate — Re-render Instead
When you start writing apps with React, you may be surprised by how it simplifies the flow of building user interfaces, thanks to the declarative patterns inspired by the library.
For instance, when using other libraries, hiding and showing elements on the screen usually looks a bit like this:
In the snippet above, we’re listening to a click event, and we manually access the DOM to hide or show the element when the event happens. With React, however, we can rely on something called the component state to determine how a component should render:
Then we’ll re-render our component every time there is a change in state. (See what I mean by declarative style?) This allows us to only think of the bottom line, which is what our component should look like given a certain state.
With React, we don’t have to worry about manually manipulating the DOM and accounting for all of the intricacies that come with that as our UI elements get more complex. Instead, we tell our components what they should look like and let it happen.
Just the Beginning
This is just a quick overview of why you may want to learn React — and I haven’t even mentioned how it can help you tinker with native mobile apps almost for free. Then there’s the fact that some big players in the industry, even outside the web and mobile realms, are using React to build user interfaces. For example, apps built for virtual reality devices and smart TVs are built with React but rendered natively, which is great for the developers and keeps those apps highly performant.
While it’s tough to stay on top of every new technology, there are those that do stand out among the rest, such as React. It’s definitely a game-changer and will forever impact how we write apps for the web, mobile, and beyond.