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

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -