• Stars
    star
    351
  • Rank 120,906 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy-to-use React component for websocket communications.

react-websocket contributions welcome FOSSA Status

react-websocket is a easy-to-use React component for websocket communications.

Help Wanted

Things here are running very slowly as I have a lot of other stuff to take care at the moment so please don't be upset if I don't answer your question or if a PR sits unreviewed for a few days or weeks. Anyone interested in helping it move faster can help by submitting or reviewing PR's and answering each other's questions.

Installing

npm install --save react-websocket

Usage

  import React from 'react';
  import Websocket from 'react-websocket';

  class ProductDetail extends React.Component {

    constructor(props) {
      super(props);
      this.state = {
        count: 90
      };
    }

    handleData(data) {
      let result = JSON.parse(data);
      this.setState({count: this.state.count + result.movement});
    }

    render() {
      return (
        <div>
          Count: <strong>{this.state.count}</strong>

          <Websocket url='ws://localhost:8888/live/product/12345/'
              onMessage={this.handleData.bind(this)}/>
        </div>
      );
    }
  }

  export default ProductDetail;

Properties

url

required The url the websocket connection is listening to.

onMessage

required The callback called when data is received. Data is JSON.parse'd

onOpen

The callback called when the connection is successfully opened.

onClose

The callback called when the connection is closed either due to server disconnect or network error.

debug

default: false Set to true to see console logging

reconnect

default: true

accelerated reconnection time

License

FOSSA Status

More Repositories

1

tangrowth

Python3.5 async crawler example with aiohttp and asyncio
Python
147
star
2

tornado-user-authentication-example

small code example for user login / logout
Python
25
star
3

tornado-uvloop

super simple uvloop class for tornado framework
Python
15
star
4

dict2form

python dictionary object to html5 json form generator
Python
9
star
5

f-keyboard

Turkish Classic F keyboard layout like MS & Linux
5
star
6

free-book-cover

Free Book Cover Mockup
5
star
7

sehir

A function that returns unified Turkish city names
TypeScript
5
star
8

skeleton-itcss

ITCSS blank scheme on gulp
JavaScript
3
star
9

pipi

shortcut install & freeze pip packages
Python
3
star
10

orion8

A blockchain database for BlockStack projects to keep relations on a trustable network which uses Websockets for p2p communication.
JavaScript
3
star
11

torethink

Rethinkdb Wrapper For Tornado Framework
Python
3
star
12

boilerplate

application boilerplate for cross development
Objective-C
3
star
13

blockchain-javascript-boilerplate

ES6 Blockchain Example
JavaScript
2
star
14

thinker

Rethinkdb wrapper for asyncio in Python 3.5+
Python
2
star
15

react-tab-bar

React sliding tab component
TypeScript
2
star
16

cython_boilerplate

Cython Boilerplate
Python
2
star
17

tornado-localization-demo

Tornado Localization Example
Python
2
star
18

dashboard-feature-flag

For demo purposes
TypeScript
2
star
19

angular-nativescript-firebase-akita-starter

This arose from the need to have a way to prototype cross-platform apps quickly. Thus, this starter app includes a basic angular app, with Material for UI, Akita for state management, firebase for a backend, and nativescript for mobile.
JavaScript
1
star
20

huhu

An experimental script language for kids, written in Python
Python
1
star
21

mehmetkose.github.io

Personal Website
HTML
1
star
22

my_git_project

a tryout project for the "Jump Start Git" book.
1
star
23

python_background_jobs

an example of python background jobs with bash
Python
1
star
24

nextjs-forestry

JavaScript
1
star
25

32dk

32dk.com Tutorial Files
1
star
26

fupio

Decentralized Autonomous Zone.
JavaScript
1
star
27

yazilimsal

1
star
28

react-drag-dealer

JavaScript
1
star