Like many others, I was initially cynical about Facebook and the response to Instagram. Initial demonstrations of the JavaScript language extension of React, JSX, made many developers uncomfortable. We had been working for years to differentiate HTML and JavaScript, but it seemed that Respond merged them. Some have challenged the need for another library on the client side, in an ocean full of them.
React has proven incredibly popular, as it turns out, both on my own projects and with many others across the world, including major companies like Netflix. And now the platform has been put onto the mobile with React Local. React Native is a great choice to create powerful iOS and Android apps that feel at home on their respective platforms, all while building on any previous experience in web development.
React Overview
Described as "A JavaScript library to create user interfaces" by its developers, React focuses on the display portion of your application. More concretely, this means that when you write a React Native app, your view code will consist of writing React components, which are tiny pieces of code explaining how a portion of your app will look based on some collection of input data. Let's look at a small component of example that can be used to show a simple button. (I omit styles, for clarity's sake.)
This Button part has two pieces of input data: onPress, which is a callback function for when pressing the button; and text, which is the string to be displayed within the button. The XML-like structure that the render function returns is called JSX, which is syntactic sugar for calls to the function Respond. And TouchableOpacity and Text are existing components included with Native React. Now that this Button feature has been developed, with consistent actions and styling, it can be used several times in the application.
Though this is a simple example, it shows how a piece by piece Respond app is designed. Continuing in this way, you can build components which reflect that abstraction layers. You can, for example, build a ButtonGroup component that contains several buttons connected to it. And building on that, you can write components which represent whole screens. Also as the device grows considerably larger, components at each stage remain understandable and manageably sized.
Truly Native
Most JavaScript-based mobile apps use Cordova, or a framework that's based on it, like the common Ionic or Sencha Touch. You're able to make calls to native APIs with Cordova, but the majority of your software will be HTML and JavaScript within a WebView. Although you can approximate native components – and you can definitely create a great UI with HTML and JS – there's no Cordova app that matches the look and feel of a real native app. The little things-such as acceleration scrolling, keyboard actions, and navigation-all add up and can create unpleasant interactions for your customers when they're not behaving as planned.
While you still write JavaScript with React Native, the components you create end up rendering as native widgets on the platform. If you're familiar with Reacting to the Net, you'll feel at home. And if you've written apps in Java or Objective-C you can know several of the components of React Native instantly.
The best feature of react when it was initially released for the web was to render the view layer of your device a pure state production. As a developer, this means that you simply decide what your view will look like based on input data, instead of making imperative adjustments to view components (for example, programmatically modifying the text or color of a button by calling a function on it), and Respond smartly makes the adjustments for you when the state changes.
This change in thought could make building UIs dramatically simpler. We've all used apps where the UI reaches a weird unintended state after taking a direction the creator wasn't looking for. With Respond, these bugs are much easier to monitor. You don't have to care as much about the user's journey through the device as you do, instead concentrate on making sure that your view statements can accommodate all possible shapes for the state of your app. That's a lot easier problem to tackle-and check for. The machine also understands it more quickly, and changes to the static analysis and type systems would only make it easier to spot such glitches.
Native component definitions look and function pretty much like web component reaction, but target native UI widgets instead of HTML. So you can use a < View > instead of using a < div > (which is converted to a native UIView on iOS, and on Ios, android.view). As data changes for your components, React Native will determine what needs to be modified in your view, and will make the required calls to whatever native UI widgets are displayed.
And it is fast! JavaScript isn't as fast as native code can be, but JavaScript and Respond Native are more than able to keep the device running at 60 frames per second for most of the tasks. Under the hood, the JavaScript code runs on its own thread, separate from the thread of the main UI. So even though your device runs a complex logic, your UI can still animate or scroll at 60fps smoothly, as long as the JS thread doesn't block the UI.
Many software frameworks promise to let you make a great Android and iOS device, but the product always ends up somewhere in the middle without feeling very native to either one. By supporting the native platforms but also allowing the app to share much of its codebase between platforms, React Native allows developers to create amazing native apps that their customers would love, without the increase in budget building that might require two separate apps.
EASILY UNDERSTANDABLE
Some of the biggest benefits of React is how open it is to even those who are unfamiliar with it. Most frameworks allow you to study a long list of terms that are only useful within that context, while ignoring the basics of the language. Reacting does its very best to do the opposite. Take the difference between rendering a portion of a friends list in React Native vs Ionic (AngularJS) as an example.
With Ionic, you use the command ngRepeat. Let's assume we have an array of friends with the following fields each: first name, last name and is online. Yet we just want to view those friends who are online right now. Here's our checker:
our view:
This code snippet poses some immediate concerns if you aren't familiar with Ionic / AngularJS. What's the$scope? Which is Filter Syntax? And how can I add more behaviour, like sorting the friends list?
With Respond Native, using the built-in filter and map functions, you make use of your existing language fundamentals awareness.
Although the React Native snippet still poses some concerns (What does React.createClass do? What is rendering?), the fact that the majority of the code here is just standard JavaScript means that beginners can find it more accessible and tenable.
As an experienced developer, you'll save time using standard language features you already learn, and make your code more accessible to other developers. Perhaps just as importantly, React acts as an outstanding teaching resource if you are less familiar with JavaScript. Whether you haven't learned how to use maps or filters yet, practicing React will also teach you these. NgRepeat instruction just teaches you ngRepeat.
And this is before considering mobile production on multiplatforms. While in a React Native project, which targets both iOS and Android, there will be some pieces of platform-specific code, the majority will be shared and a JavaScript developer will understand all this.
Vibrant Ecosystem
Since most of your React Native code is just plain JavaScript, it reaps the advantages of all language advances and their ecosystem. Instead of waiting for all the array manipulation functions you want to enforce on your System developers, why not just use lodash? Only use Moment.js to control or show the dates and times. And all those beautiful new features of the ES6 language you've been waiting for to try out? React is not only a perfect match, their use is encouraged!
Some libraries are especially suitable for use with React Native, thanks to its declarative views. One that I would be remiss in not considering is redux. Described as a "predictable state container," redux is a great library to control the state of your application. Redux is highly testable, and allows small functions to write which are clear about what data they modify. If that way your state changes are written, your app can take advantage of powerful features, such as global undo / redo and hot reload.
Conclusion
I had a lot of fun learning and developing with React Native, between the ease of creation, the quality of the apps developed with it, and the richness of the platform and ecosystem.
As a reputed Software Solutions Developer we have expertise in providing dedicated remote and outsourced technical resources for software services at very nominal cost. Besides experts in full stacks We also build web solutions, mobile apps and work on system integration, performance enhancement, cloud migrations and big data analytics. Don’t hesitate to get in touch with us!
This article is contributed by Ujjainee. She is currently pursuing a Bachelor of Technology in Computer Science . She likes most about Computer Engineering is that it allows her to learn and be creative. Also, She believes in sharing knowledge hence is very fond of writing technical contents for the same. Coding, analyzing and blogging are things which She can keep on doing!!
Comments