Skip to content

๐Ÿ”ƒ WebSocket API wrapped as a component for React Native

License

Notifications You must be signed in to change notification settings

fredbt/react-native-websocket

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

react-native-websocket

WebSocket API wrapped as a component for React Native



Built with โค๏ธŽ by Tiaan and contributors

Table of Contents

Table of Contents
  • About
  • Install
  • Usage
  • Contribute
  • License
  • About

    This module provides a simple component wrapper around the the WebSocket API. It provides a declarative way of handling a WebSocket connection.

    Install

    $ npm install --save react-native-websocket
    # OR
    $ yarn add react-native-websocket

    Usage

    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>
        )
      }
    }

    Contribute

    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.

    License

    Licensed under the MIT License.

    About

    ๐Ÿ”ƒ WebSocket API wrapped as a component for React Native

    Resources

    License

    Stars

    Watchers

    Forks

    Packages

    No packages published

    Languages

    • JavaScript 100.0%