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

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -