React Native

React Native and Socket.io

React Native finally supports Websockets. Which is awesome, however there is one gotcha with socket.io.

1) npm install socket.io-client. This will just pull down the socket.io javascript client

2) Everything works great but there is one issue that window.navigator.userAgent doesn't exist. Socket.IO checks to deal with some browser incosistencies but we don't care. So all we have to do is create it. However make sure you require react-native first!

Just like so

window.navigator.userAgent = "react-native";

var io = require('socket.io-client/socket.io');

Now you can do as you please with your new glorious websockets.

Liked this content?

Get notified more about React Native!

No Spam! We Promise!

Related Content

Custom Handling the Android Back Button with React Navigation

In this lesson we'll explore setting up a stack navigator in React Navigation. We'll create a custom component that uses withNavigation to allow us to listen to navigation transitions. Using the BackHandler from React Native we can ask the screen if custom needs are required when the hardware back button is pressed. Finally we'll prompt the user if they want to navigate.

Conditional JavaScript Callbacks with Reanimated in React Native

In this lesson we'll explore how to setup a draggable circle. Then we'll dive into using the call method to create JavaScript callbacks whenever certain conditions are met inside of Reanimated.

Custom Handling the Android Back Button with React Navigation

In this lesson we'll explore setting up a stack navigator in React Navigation. We'll create a custom component that uses withNavigation to allow us to listen to navigation transitions. Using the BackHandler from React Native we can ask the screen if custom needs are required when the hardware back button is pressed. Finally we'll prompt the user if they want to navigate.

Conditional JavaScript Callbacks with Reanimated in React Native

In this lesson we'll explore how to setup a draggable circle. Then we'll dive into using the call method to create JavaScript callbacks whenever certain conditions are met inside of Reanimated.