Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux With Socket #20

Open
SambitPrakash opened this issue Aug 25, 2017 · 0 comments
Open

Redux With Socket #20

SambitPrakash opened this issue Aug 25, 2017 · 0 comments

Comments

@SambitPrakash
Copy link

SambitPrakash commented Aug 25, 2017

Hey @buckyroberts, I am following your redux tutorial in youtube and it's awesome. You made redux concept so easy.
But now, i am facing one issue in redux. If you can help me out from this, i will be very thankful.

I am trying to use socket.io in my react-native project. I created one SocketHelper.js file and i put all my events over there. Please check my code below.


import React from 'react'
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
window.navigator.userAgent = 'react-native';
import io from 'socket.io-client/dist/socket.io'
import { setRouteAction } from '../../ReduxModel/Actions/BusRouteAction'

var socket;

export function socketListener () {

    socket = io('localhost://3000', {jsonp: false});

    socket.on('connectionCheck', (response)=> {
        console.log('socket connection' + response.message);
    });

    socket.on('getRoutesResponse', (response) => {
        console.log('route json response : ' + response);
        console.log(props)
    });
}

function mapStateToProps(state) {
    return {
        user: state.user
    };
}

function matchDispatchToProps(dispatch) {
    return bindActionCreators({
        routes: setRouteAction
    }, dispatch)
}

export default connect(mapStateToProps, matchDispatchToProps);

and the issue is as i am not using a class here, how i can use routes (i.e. inside the matchDispatchToProps) as props to dispatch my data.

Please let me know, if i am missing any concept or anything i am doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant