1.0.3 • Published 3 years ago

@fkul/react-cf-ws-api v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

react-cf-ws-api

React WebSocket API for Crypto Facilities.

Getting started

yarn add @fkul/react-cf-ws-api

Interface

type CfWs = {
  subscribePub(
    feed: string,
    products: string[],
    callback: (data?: any) => void
  ): void
  unsubscribePub(feed: string, products: string[]): void
  getSubscriptionStatus(feed: string): string | null
}
  • subscribePub - subscribes to a public feed
  • unsubscribePub - unsubscribes from a public feed
  • updateSubscription - updates an existing subscription
  • getSubscriptionStatus - gets the status of a subscription

Example

import { useCfWs } from '@fkul/react-cf-ws-api';

const Component = () => {
  const ws = useCfWs()

  // the callback function
  const onFeedData = (data) => {}

  // subscribe
  ws.subscribePub("some_feed_name", ["som_product_id"], onFeedData)

  return <></>
}

export default Component

Building

yarn build

Testing

yarn test