reactjs - Where should I call socket.on in react? -
currently m using socket.on in constructor. cannot use setstate there. life cycle should use call socket.on ?
socket.on('users', function (user) { switch (user.meta.action) { case 'create': store.dispatch(appenduser(user.data)); break; case 'update': store.dispatch(replaceuser(user.data)); break; case 'delete': store.dispatch(deleteuser()); break; } });
since want websockets connection established when initialize react component, should in componentdidmount
. way able use setstate
.
Comments
Post a Comment