Book Image

Getting Started with React Native

Book Image

Getting Started with React Native

Overview of this book

React Native is a game-changing approach to hybrid mobile development. Web developers can leverage their existing skills to write mobile applications in JavaScript that are truly native without using cross-compilation or web views. These applications have all of the advantages of those written in Objective-C or Java, combined with the rapid development cycle that JavaScript developers are accustomed to. Web developers who want to develop native mobile applications face a high barrier to entry, because they are forced to learn platform-specific languages and frameworks. Numerous hybrid technologies have tried to simplify this process, but have failed to achieve the performance and appearance that users expect. This book will show you all the advantages of true native development that React Native has without the steep learning curve, leveraging the knowledge you already have. We do this by getting you up and running quickly with a sample application. Next, we’ll introduce you to the fundamentals of creating components and explain how React Native works under the hood. Once you have established a solid foundation, you will dive headfirst into developing a real-world application from start to finish. Along the way, we will demonstrate how to create multiple screens and navigate between them,use layout and style native UI components, and access native APIs such as local storage and geolocation. Finally, we tackle the advanced topic of Native modules, which demonstrates that there are truly no limits to what you can do with React Native.
Table of Contents (15 chapters)

The Virtual DOM


Do you know how to write a JavaScript function? If you do, that's great! You're well on your way to understand how React and React Native work under the hood. What do we mean exactly? Well, when you research how React works, you'll eventually encounter someone explaining it in the following manner:

UI = f(data)

You may say, Nerd alert! How is this helpful? Well, it's saying that your UI is a function of your data. To put it in more familiar terms, let's say that:

var todos = function(data) { return data.join( " -- " ) }

You can call the function with an array of data, such as:

var ui = todos( ["wake up", "get out of bed", "drag a comb across my head"] );
console.log(ui);

This is not a particularly earth-shattering code; however, you're now rendering some content, in this case to the console.

What if, all your UI rendering code could be this predictable? It can be! Let's start getting a little more advanced. What if, in addition to our todos() function, we had a function called todoItem...