You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Url is dynamic in my project. when url changes, we found action cable can't update accordingly. So I found the problem is we should use the next props but not this props as an argument for componentWillMount in componentWillReceiveProps(https://github.com/cpunion/react-actioncable-provider/blob/master/lib/index.js#L41); Below is my code for reference:
componentWillMount: function () {
this.connect(this.props);
},
componentWillUnmount: function () {
if (!this.props.cable && this.cable) {
this.cable.disconnect()
}
},
connect: function (props) {
console.log("action cable url on provider ============>", props.url)
if (props.cable) {
this.cable = props.cable
} else {
this.cable = actioncable.createConsumer(props.url)
}
},
componentWillReceiveProps: function (nextProps) {
// Props not changed
if (this.props.cable === nextProps.cable &&
this.props.url === nextProps.url) {
return
}
// cable is created by self, disconnect it
this.componentWillUnmount()
// create or assign cable
this.connect(nextProps)
},
The text was updated successfully, but these errors were encountered:
Url is dynamic in my project. when url changes, we found action cable can't update accordingly. So I found the problem is we should use the next props but not this props as an argument for componentWillMount in componentWillReceiveProps(https://github.com/cpunion/react-actioncable-provider/blob/master/lib/index.js#L41); Below is my code for reference:
The text was updated successfully, but these errors were encountered: