How to do it...

  1. First, let's create the App.js file and import all the dependencies we'll be using:
import React, { Component } from 'react';import {  Dimensions,  ScrollView,  StyleSheet,  Text,  TextInput,  SafeAreaView,  View,  Platform} from 'react-native';
  1. On the state object, we'll declare a history property. This property will be an array for holding all of the messages that have been sent back and forth between users:
export default class App extends Component {  state = {    history: [],  };
    // Defined in later steps 
} 
 
const styles = StyleSheet.create({ 
  // Defined in later steps 
}); 
  1. Now, we need to integrate WebSockets into our app by connecting to the server and setting up the callback functions for receiving messages, errors, and when ...

Get React Native Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.