Javascript 将循环结构转换为json、Phoenix和React

Javascript 将循环结构转换为json、Phoenix和React,javascript,json,reactjs,react-native,phoenix-framework,Javascript,Json,Reactjs,React Native,Phoenix Framework,嗨,我有一个将循环结构转换为JSON的错误 这就是有效的方法 Main.js componentWillMount(){ const getSocket=()=>{ const url=config.local?`ws://${config.host}/socket`:`wss://${config.host}/socket` const params={guardian_token:“foobar”} 返回新套接字(url,{params:params}); } this.socket=get

嗨,我有一个将循环结构转换为JSON的错误

这就是有效的方法 Main.js

componentWillMount(){
const getSocket=()=>{
const url=config.local?`ws://${config.host}/socket`:`wss://${config.host}/socket`
const params={guardian_token:“foobar”}
返回新套接字(url,{params:params});
}
this.socket=getSocket();
}
Relay.QL`query{user}`,}}
hideNavBar={true}
图标={TabIcon}
MaterialConName='perm-identity'
套接字={this.socket}
/>
Child.js

componentWillMount(){
/*连接到websocket*/
/*也许这应该作为道具传下去*/
this.props.socket.connect();/*{console.log(“ok”)})
.receive(“error”,resp=>{console.log(“无法加入”,resp)})
on(“new:notification”,()=>this.props.relay.forceFetch());
}
但是如果我换成这个

孩子

//this.props.socket.connect()

和加载项Main

this.socket.connect()

我得到这个错误

    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}
                    />
    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());
}