Tried two ways:
call
connectToServer()
from action creator withinStarter
component incomponentDidMount();
and dispatch like this:let socket = new Socket('ws://address/socket'); socket.connect(); dispatch({ type: Constants.SESSION_SAVE_SOCKET, socket: socket, }); const lobbyChannel = socket.channel('lobby'); lobbyChannel.join() .receive('ok', () => { dispatch({ type: Constants.SESSION_LOBBYCHANNEL_RECEIVE_OK, }); dispatch({ type: Constants.SESSION_SAVE_LOBBYCHANNEL, lobbyChannel: lobbyChannel, }); }).receive('error', (payload) => { dispatch({ type: Constants.SESSION_LOBBYCHANNEL_RECEIVE_ERROR, }); });
Next I receive state by redux's mapStateToProps connect
.
The result is component is called four times and props are empty at the result.
- put all logic into the reducer, but the result is: component is rendered with empty props (undefined properties) and moment after I see in console logs that connection is established, but component is already rendered.
How to deal with such a issue? Thanks for any suggestions.