Book Image

React Native Cookbook - Second Edition

By : Daniel Ward
4 (1)
Book Image

React Native Cookbook - Second Edition

4 (1)
By: Daniel Ward

Overview of this book

If you are a developer looking to create mobile applications with maximized code reusability and minimized cost, React Native is what you need. With this practical guide, you’ll be able to build attractive UIs, tackle common problems in mobile development, and achieve improved performance in mobile environments. This book starts by covering the common techniques for React Native customization and helps you set up your development platforms. Over the course of the book, you’ll work through a wide variety of recipes that help you create, style, and animate your apps with built-in React Native and custom third-party components. You’ll also develop real-world browser-based authentication, build a fully functional audio player, and integrate Google Maps in your apps. This book will help you explore different strategies for working with data, including leveraging the popular Redux library and optimizing your app’s dataflow. You’ll also learn how to write native device functionality for new and existing React Native projects and how app deployment works. By the end of this book, you'll be equipped with tips and tricks to write efficient code and have the skills to build full iOS and Android applications using React Native.
Table of Contents (17 chapters)

Establishing real-time communication with WebSockets

In this recipe, we will integrate WebSockets in a React Native application. We are going to use the Hello World of WebSockets applications, that is, a simple chat app. This app will allow users to send and receive messages.

Getting ready

To support WebSockets on React Native, we will need to run a server to handle all connected clients. The server should be able to broadcast a message when it receives a message from any of the connected clients.

We'll start with a new, empty React Native app. We'll name it web-sockets. In the root of the project, let's add a server folder with an index.js file inside of it. If you don't already have it, you'll need...