From native to React Native

  • After developing mobile applications for more than eight months, I had the opportunity of joining a project that was being developed using React Native, an open source JavaScript library that, according to its documentation, lets you build mobile apps using only JavaScript.
  • React Native it’s a very new technology announced on the beginning of 2015 – just a couple years ago – where the main objective is to allow the development of mobile apps using the same design as React, letting you compose a rich mobile UI from declarative components.
  • There were a lot of things that I enjoyed about developing a React Native app, like the flexibility that you can get out of JavaScript after get used on how it works and the core concepts of React.
  • I had a really great time working with React Native and after developing the base components I felt that creating new screens was even faster than coding on native languages.
  • Another great factor that makes it easy to develop apps using React Native is the fact that the JavaScript community is huge, this means lots and lots of knowledge shared on Stack Overflow.

React Native main objective is to allow the development of mobile apps using the same design as React.

@CheesecakeLabs: NEW ARTICLE: From native to #reactnative by @andriofrizon2 ⚛️

After developing mobile applications for more than eight months, I had the opportunity of joining a project that was being developed using React Native, an open source JavaScript library  that, according to its documentation, lets you build mobile apps using only JavaScript. I always loved challenges and learning new things, so I immediately accepted this opportunity.

React Native it’s a very new technology announced on the beginning of 2015 – just a couple years ago – where the main objective is to allow the development of mobile apps using the same design as React , letting you compose a rich mobile UI from declarative components.

If you haven’t heard about these technologies, you should definitely read about – but for now let’s focus on my experience when I started using them.

First steps

There were so much stuff to learn at the beginning that I felt overwhelmed. One of the biggest challenges when I started was JavaScript itself: a high-level, multi-paradigm, dynamic, weakly typed, object-based programming language.

Migrating from Swift, the weakly typed treat was one of the biggest differences at first. This means it is not necessary to determinate the type of variables or parameters of functions at compiling time, allowing, for example – and you can see on the sample code below – the function argument arg to be either a number, a string, an object or even a function, thus being impossible to know that just by reading the method declaration.

A more concise way to write functions is to use arrow functions (changing the way functions are binded):

The next step was learning the principles of React, which forces the developer to break the application into small components. That was something that I was already used to while developing native apps, so it was an easy step. The only small change at this stage was to learn how to style the components. Styles on React Native are done using JavaScript objects with properties that are very similar with CSS.

The big challenge: Redux

When developing projects using React, one of the first things that you have to understand is that you have to develop thinking on the state of the view/component. Redux is a small library written by Dan Abramov in 2015 that helps the developer to manage the state of the whole application in a single immutable object, working as the source of truth for the app.

Besides that, it also works in a reactive manner: meaning that when the redux state is updated, all the components that are connected to it will get the new information and can be re-rendered automatically, updating the UI when some action happens on the app.

This is very different from what I was used to do on native apps, especially considering that I was only developing using MVC and VIPER architectures, where the data flows bidirectionally. Managing the state when the information can be flowing in multiple directions sometimes get really tricky.

Redux aims to centralize all the information, but it can be hard to grasp at the beginning. After a while you’ll have an ‘ah-ha’ moment and everything will start to make sense.

Things I enjoyed the most and not so much

There were a lot of things that I enjoyed about developing a React Native app, like the flexibility that you can get out of JavaScript after get used on how it works and the core concepts of React.

Breaking up the views into small components improves the code reuse and makes it easy to see the layout and how the components are combined. It is possible to create abstractions over those components allowing them to be extended, boosting maintainability.

One last thing that is definitely worth mentioning is the hot reload feature. I was amazed when I start developing and could see the changes I was making on the layout immediately reflected on the phone. It saves a lot a time when creating new components/screens or when you need to tweak the design.

On the other hand, there were of course a few things that I didn’t like about the stack. To begin with I could mention the steep learning curve and the huge amount of libraries that I had to study in order to succeed the development of the application.

Another huge problem that I faced on the beginning was with navigation. Navigation is still a huge challenge on React Native and there are some open source libs to aid that task, but they are far from the flexibility offered by native coding.

Is it worth trying?

At the beginning, there was so much to learn that I didn’t feel productive at all, but I had my mind prepared for that. After a couple weeks, when I had time to digest all the concepts and practice them all, everything started to change.

I had a really great time working with React Native and after developing the base components I felt that creating new screens was even faster than coding on native languages.

Besides that, learning the way redux works and manage states also opened my mind for a lot of new possibilities even when developing natively. I strongly believe that knowledge is never enough.

Another great factor that makes it easy to develop apps using React Native is the fact that the JavaScript community is huge, this means lots and lots of knowledge shared on Stack Overflow.

Last but not least, the one thing that boosted my learning experience of React Native was working next to Daniel Leite, a front-end specialist on Cheesecake Labs that helped me understand deeply how the library works and how I should use JavaScript in the correct way.

From native to React Native