Tutorial by Examples

var ws = new WebSocket('ws://host.com/path'); ws.onopen = () => { // connection opened ws.send('something'); // send a message }; ws.onmessage = (e) => { // a message was received console.log(e.data); }; ws.onerror = (e) => { // an error occurred console.log(e...
It should be noted that Fetch does not support progress callbacks. See: https://github.com/github/fetch/issues/89. The alternative is to use XMLHttpRequest https://developer.mozilla.org/en-US/docs/Web/Events/progress. fetch('https://mywebsite.com/mydata.json').then(json => console.log(json)); ...
var request = new XMLHttpRequest(); request.onreadystatechange = (e) => { if (request.readyState !== 4) { return; } if (request.status === 200) { console.log('success', request.responseText); } else { console.warn('error'); } }; request.open('GET', 'https://my...
Redux is the most common state management library used with React-Native. The following example demonstrates how to use the fetch API and dispatch changes to your applications state reducer using redux-thunk. export const fetchRecipes = (action) => { return (dispatch, getState) => { f...
Install socket.io-client npm i socket.io-client --save Import module import SocketIOClient from 'socket.io-client/dist/socket.io.js' Initialize in your constructor constructor(props){ super(props); this.socket = SocketIOClient('http://server:3000'); } Now in order to use you...
Configure For web request you can also use library axios. It's easy to configure. For this purpose you can create file axios.js for example: import * as axios from 'axios'; var instance = axios.create(); instance.defaults.baseURL = serverURL; instance.defaults.timeout = 20000;] //... //and...

Page 1 of 1