WebSocket API wrapped as a component for React Native
Built with โค๏ธ by Tiaan and contributors
This module provides a simple component wrapper around the the WebSocket API. It provides a declarative way of handling a WebSocket connection.
$ npm install --save react-native-websocket
# OR
$ yarn add react-native-websocket
import React, { Component } from 'react'
import { AppRegistry, View } from 'react-native'
import WS from 'react-native-websocket'
export default class Example extends Component {
render () {
return (
<View style={{flex: 1}}>
<WS
ref={ref => {this.ws = ref}}
url="wss://echo.websocket.org/"
onOpen={() => {
console.log('Open!')
this.ws.send('Hello')
}}
onMessage={console.log}
onError={console.log}
onClose={console.log}
reconnect // Will try to reconnect onClose
/>
</View>
)
}
}
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the standard-readme specification.
Licensed under the MIT License.