Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bs-react-native-websocket

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs-react-native-websocket

Buckle Script bindings for react-native-websocket

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bs-react-native-websocket

This package provide Reasonml bindings for react-native-websocket component.

Installation

$ yarn add bs-react-native-websocket react-native-websocket

Then update your bsconfig.json, add bs-react-native-websocket to bs-dependencies.

"bs-dependencies": ["bs-react-native-websocket"]

Usage

Usage is very similliar to react-native-websocket.

Example:

type state = {
  socketRef: ref(option(ReasonReact.reactRef)),
};

let setSocketRef = (theRef, {ReasonReact.state}) =>
  state.socketRef := Js.Nullable.toOption(theRef);

let component = ReasonReact.reducerComponent("Component");

let make =
    (
      _children,
    ) => {
  ...component,
  initialState: () => {socketRef: ref(None)},
  render: self =>
    <View>
      <ReactNativeWebsocket
        url="ws://localhost:5000"
        onOpen={() => Js.log("successfull connection")}
        onMessage={
          event =>
            Js.log(event) // event is a Js.dict object
        }
        onError={() => Js.log("get error")}
        onClose={() => Js.log("connection closed")}
        ref={self.handle(setSocketRef)}
        reconnect=true
      />
    </View>,
};

Example of sending data:

// socket is ref to ReactNativeWebsocket component
// data is a stringifiedData that you want to send
ReactNativeWebsocket.send(socketRef, data);

License

MIT

Contributing

PR's are welcome!

FAQs

Package last updated on 07 Sep 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc