Giter Site home page Giter Site logo

freshy969 / react-pusher-hoc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fel1xw/react-pusher-hoc

0.0 1.0 0.0 388 KB

Handle websocket events (pusher.com) in React, without the tears ๐Ÿ˜ญ.

License: MIT License

JavaScript 8.10% TypeScript 91.90%

react-pusher-hoc's Introduction

logo

npm version Build Status Blazing Fast Coverage Status Dependencies License: MIT gzip size Known Vulnerabilities

Install

npm install react-pusher-hoc --save
# or
yarn add react-pusher-hoc

Usage

  1. To use react-pusher, you need to pass the pusher instance to the PusherProvider as following:
import { PusherProvider } from 'react-pusher-hoc';
import Pusher from 'pusher-js';

const pusherClient = new Pusher({
  <your_config>...
});

<PusherProvider value={pusherClient}>
  <App />
</PusherProvider>
  1. Then you can wrap your component with the HOC (where itemChannel is the channel name and add is the event name delimited by .):
import withPusher from 'react-pusher-hoc';

const ItemList = ({ items }) => (
  <ul>
    {items.map(item => <span key={item}>{item}</span>)}
  </ul>
);

const mapEventsToProps = {
  mapPropsToValues: props => ({
    items: [],
  }),
  events: {
    'itemChannel.add': (item, state, props) => ({
      items: state.items.concat(item),
    }),
  }
};

export default withPusher(mapEventsToProps)(ItemList);

You need to provide initialValues through the mapPropsToValues function.

Author

Support

If you like the project and want to support my work, you can think about buy me a coffee :)

paypal

react-pusher-hoc's People

Contributors

fel1xw avatar willnguyen1312 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.