您好我有将循环结构转换为JSON 错误。
这是有效的 Main.js
componentWillMount(){
const getSocket = () => {
const url = config.local ? `ws://${config.host}/socket` : `wss://${config.host}/socket`
const params = {guardian_token:"foobar"}
return new Socket(url, {params: params});
}
this.socket = getSocket();
}
<Scene
key="profile"
title='Profile'
component={Profile}
queries={{user: () => Relay.QL`query { user } `,}}
hideNavBar={true}
icon={TabIcon}
materialIconName='perm-identity'
socket={this.socket}
/>
Child.js
componentWillMount(){
/* Connect to the websocket */
/* Maybe this should be passed down as a prop ? */
this.props.socket.connect(); /*<------------*/
let channel = this.props.socket.channel("notifications:" + this.props.user.id)
channel.join()
.receive("ok", resp => {console.log("ok")})
.receive("error", resp => {console.log("Unable to join", resp)})
channel.on("new:notification", () => this.props.relay.forceFetch());
}
但如果我改成这个
子
//this.props.socket.connect();
并添加Main
this.socket.connect();