reactjs - polling api every x seconds with react -


i have monitoring data update info on screen each 1 or 2 seconds. way figured using implementation:

componentdidmount() {     this.timer = setinterval(()=> this.getitems(), 1000);   }    componentwillunmount() {     this.timer = null;   }    getitems() {     fetch(this.getendpoint('api url endpoint"))         .then(result => result.json())         .then(result => this.setstate({ items: result }));   } 

is correct approach?

it not correct, mast process "ws" protocol. easy use: in create store fragment connect websocket store , call dispatch({ type: receive_message, payload: {room, message....} }); when send message can receive , put in right place of redux store;


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -