Releases: cpunion/react-native-actioncable
Releases · cpunion/react-native-actioncable
v0.0.2
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
}