Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Last active August 13, 2016 21:17
Show Gist options
  • Save samcorcos/5993878324101e2304d43f9fce5c49cc to your computer and use it in GitHub Desktop.
Save samcorcos/5993878324101e2304d43f9fce5c49cc to your computer and use it in GitHub Desktop.
import React from 'react'
import { Socket } from 'phoenix'
class App extends React.Component {
componentDidMount() {
this.socket = new Socket('http://localhost:4000/socket')
this.socket.connect()
this.configureChannel("lobby")
}
componentWillUnmount() {
this.socket.leave()
}
configureChannel(room) {
this.channel = this.socket.channel(`rooms:${room}`)
this.channel.join()
.receive("ok", () => {
console.log(`Succesfully joined the ${room} chat room.`)
})
.receive("error", () => {
console.log(`Unable to join the ${room} chat room.`)
})
}
render() {
return (
<div>
My App
</div>
)
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment