REACT NATIVE: 5 COMPREHENSIVE MISTAKES YOU DON'T WANT TO MAKE!

Regularly hailed as 'the next wave in hybrid app development', React Native is the tool of choice for building market-ready mobile applications. It provides a significant time-saving advantage for developers, promising near-immediate adaptability for both iOS and Android platforms.
Previously, we discussed the appeal of React Native and delved into the reasons for its widespread adoption. One cannot overlook that the primary strength of React Native is its capability to support cross-platform development. Nonetheless, to leverage this platform optimally, developers must possess an in-depth understanding of its entire ecosystem. A thorough grasp ensures they don't end up with convoluted JavaScript syntax that could hinder the app's user experience.
Without a doubt, React Native stands as a formidable framework for crafting top-notch, scalable applications. To truly harness its potential and realize its full advantages, developers should stay vigilant against beginner-level pitfalls and be meticulous in their approach.
In today's post on the Jung Talents blog, we will delve into the top five pitfalls to sidestep in React Native development.

Mistake #1: Poor Estimations and Not Enough Attention to Details

Alas, you can never use the exact same code for both iOS and Android because the two systems differ in terms of the page structure. This means that, as a developer, you should always prepare for dealing with two separate layouts and bear in mind different databases and backend points before forming your estimation.
Another mistake developers make when attempting to save time, is using external modules but missing to read all codes extracted from them. External modules can make the development process faster as they have completely formed codes. However, developers often forget to read all of the code or they disregard it as not necessary. This might cause issues later down the road.
When developers add external modules, they can interfere with the existing code and hinder the functionality of it. By not paying attention to details in time, developers create a much bigger workload later. This defies the purpose of saving time.

Mistake #2: Improper Redux Store Setup

Even though Redux has changed a lot over the time, the fundamental building blocks of doing anything in this tool still come down to actions, reducers, middleware, and the store. To achieve anything in this toolkit, you need to build up your knowledge on all of its major components.
The store is probably one of the most common points that newbies struggle with. Unfortunately, this is an important part of the puzzle which you cannot ignore. If the store is not set up properly, it can mess with your logic tests, debugging, and data flow of your applications.
To correctly integrate Redux into your your React Native environment, you need to:
  • Build a store hierarchy and organize your files
  • Include the first reducer function, but with extra caution and focus on what you’ll need it to do with your app
  • Add more reducers and focus on combining them
  • Think about adding middleware
  • Configure the store
Voila! That’s it. One thing to bear in mind here: Redux stores are built for big app projects. If you’re working on a small project, this tool tends to complicate things beyond necessity. For instance, if the change you make in Redux on your small project will require rewriting multiple lines of code - this is not something you really want to do through your entire app development process. Redux is the go-to resource for large-scale projects, so make sure to use it when it can truly help you.

Mistake #3: Images Are Left Unoptimized

Optimizing images in React Native applications is a task that should be dealt with maximum attention because it directly influences app’s performance.
Unoptimized images tend to eat up a lot of memory and storage. Taking care of this part of the process is very important because memory and storage are essential components for every project.
Luckily, optimizing images is not a complicated task. All you have to do is:
  • Change your image size before uploading in it into React (i.e. make sure that your images are as small as they possibly can be)
  • Use image only in WebP format to speed up load time and reduce bundle as well as binary sizes (both iOS and Android)
  • Prioritize PNG over JPG
  • Cache your images locally for fast loading
Even though optimizing images doesn’t require a lot of work, most devs tend to skip this step because it's a boring task to do. However, these sort of neglectful moves carry a lot of weight, so make sure that a single moment of laziness doesn’t cost you precious memory and storage that you’ll need for other important elements.

Mistake #4: Stateless Components and Wrong Initialization of State

When it comes to states in React Native, there are two main mistakes developers make:
  • Using stateless components at all times
  • Initiating state the wrong way
It is true that developers may turn to stateless components in React Native in order to boost performance. Because stateless components don’t have any local state or extend any class, they simply return what is given to them in DOM. This enables easy testing and gives product teams a chance to push the app faster to the market.
This was a common practice before React 16. However, it’s not as effective as it once was, nor is it ideal for all scenarios.
To speed up the process, some developers are using Pure Component, which might be a better solution because it doesn’t re-render when the parent component re-renders. There is also significant progress in the industry when it comes to making React blazing fact using other methods.
Wrong initialization of state is another mistake React Native developers make. Within the framework, the setState() function is used for initializing and retrieving the new object’s state. This is then compared to the previous state and, once this phase is done, the state gets merged with the existing one; the previous state gets sent back to the datastore.
If the initial state is set properly in advance, then the cycle continues without any issues. But developers often make mistakes here, which causes the break in this cycle. This may lead to poor app performance (e.g. the app may crash frequently).

Mistake #5: Not Writing a Unit Test

Most developers are used to working without written test units, so it’s no wonder why this step often gets ignored. However, proceeding forward with development without a proper unit test is always a risky move.
Fixing issues once everything is done and when the product has already hit the market, requires a lot of more work. Plus, making a glitchy product public tends to negatively affect both user satisfaction and the client’s reputation, so it’s best to reduce the chances of that unnecessary drama happening whenever it’s possible.
Unit tests exist for a reason. They enable us to assess various parts and features of our applications independently, and see them in action before anyone else. It’s best to test the functionality of every element of the app at the right stage and ensure that it’s working properly.
Nobody wants to release a glitchy product and lose face on a rookie mistake. Over to You
Developers are well acquainted with the feeling of frustration when they notice a mistake that forces them to rewrite a whole chunk of code or even to go back to the drawing board and start from scratch.
However, to make errors is human and that’s what helps us learn. Psychologists argue that failure is the most precious thing in terms of gaining experience, mastering new skills, and becoming better at whatever you do.
Jung Talents hope that this article helps you be aware of the most common mistakes in React Native development so that you can be cautious when getting started. Learning from mistakes is great, but it’s even better if those mistakes are not your own, right?