New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-multiplayer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-multiplayer

Multiplayer React using Firebase

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

react-multiplayer

Make your React apps multiplayer! This leverages Firebase to magically make a React component's state shared across multiple users.

Tutorial: multiplayer notepad

Creating multiplayer notepad is very simple. First, create a simple controlled textarea, just like you would with any form in React. We'll use React's two-way binding helpers to save us some typing:

/** @jsx React.DOM */

var App = React.createClass({
  mixins: [React.addons.LinkedStateMixin],
  getInitialState: function() {
    return {text: ''};
  },
  render: function() {
    return <textarea valueLink={this.linkState('text')} />;
  }
});

React.renderComponent(<App />, document.body);

Next, let's make it multiplayer by adding two lines of code.

/** @jsx React.DOM */

var App = React.createClass({
  mixins: [React.addons.LinkedStateMixin, ReactMultiplayer.Mixin],
  getInitialState: function() {
    return {text: ''};
  },
  render: function() {
    return <textarea valueLink={this.linkState('text')} />;
  }
});

ReactMultiplayer.setFirebaseRoot('https://YOUR_ID_HERE.firebase.com/');
React.renderComponent(<App />, document.body);

Bam. You're done.

Extra features

If you want finer control over how state is shared (i.e. multiple chat rooms), override getFirebaseURL():

/** @jsx React.DOM */

var App = React.createClass({
  mixins: [React.addons.LinkedStateMixin, ReactMultiplayer.Mixin],
  getInitialState: function() {
    return {text: ''};
  },
  getFirebaseURL: function() {
    return 'https://YOUR_ID_HERE.firebaseio.com/' + this.props.chatroom;
  },
  render: function() {
    return <textarea valueLink={this.linkState('text')} />;
  }
});

React.renderComponent(<App chatroom="mychat" />, document.body);

Keywords

React

FAQs

Package last updated on 20 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts