Skip to content

Releases: cpunion/react-native-actioncable

v0.0.2

04 Sep 04:49
Compare
Choose a tag to compare

Add ActionCableProvider.

You can now use ActionCableProvider to provider cable in context.

import { ActionCableProvider } from 'react-native-actioncable'

export default function Container (props) {
    return (
        <ActionCableProvider url='ws://localhost:3000/cable'>
            <MyApp />
        </ActionCableProvider>
    )
}

And use it in some UI components.

import React, { Component, PropTypes } from 'react'
import ActionCable from 'react-native-actioncable'

export default class ChatRoom extends Component {
    static contextTypes = {
        cable: PropTypes.object.isRequired
    };

    componentDidMount () {
        this.subscription = this.context.cable.subscriptions.create(
            'ChatChannel',
            {
                received (data) {
                    console.log(data)
                }
            }
        )
    }

    componentWillUnmount () {
        this.subscription &&
            this.context.cable.subscriptions.remove(this.subscription)
    }

    // ... Other code
}

v0.0.1

04 Sep 04:47
Compare
Choose a tag to compare

Basic ActionCable module.