Answer the question
In order to leave comments, you need to log in
Where is it correct to register connect if possible?
It is necessary for me that when the answer came to the server, the setUsersData action was called. Where do I need to write connect( null, mapDispatchToProps) that it was available in onmessage?
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { usersActions } from 'reducers';
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
setUsersData: usersActions.setUsersData
},
dispatch
);
export default ((wsUrl) => {
let ws;
ws = new WebSocket(wsUrl);
ws.onopen = () => {
console.log('WS open');
};
ws.onmessage = (message) => {
console.log(message.data);
// setUsersData(message.data);
};
const emit = (message) => {
if (ws.readyState !== ws.CONNECTING) {
ws.send(message);
}
};
return { emit };
})('ws://localhost:3000');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question