When using react-native-web NetInfo works fine for Android and iOS but is not working for web.
To confirm the code being run for web is the same as Android I console log in the componentDidMount
and both Android and Web display the text. However the events dont seem to be working for the web version.
// src/App.js
import React from 'react';
import { Provider } from 'react-redux';
import store from './utilities/storage/store';
import EntryScreen from './screens/EntryScreen';
import Routing, { Router } from './utilities/routing/index';
import { NetInfo } from 'react-native';
const Route = Routing.Route;
class App extends React.Component {
componentDidMount() {
console.log('App mounted');
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
}
/**
* Listens for any internet connectivity changes.
* @param isConnected The internet connection status
*/
handleConnectivityChange = (isConnected) => {
console.log ('bam');
console.log ('Connected:', isConnected);
};
render() {
return (
<Provider store={store}>
<Router>
<Route path="/" component={EntryScreen} />
</Router>
</Provider>
);
}
}
export default App;
I would expect, based on the documentation that NetInfo works for web as well as Android. If it does not can someone provide a way to do this please.
"react": "^16.2.0",
"react-art": "^16.2.0",
"react-dom": "^16.2.0",
"react-native": "0.57.8",
"react-native-web": "0.9.13",
答案 0 :(得分:0)
NetInfo缺少某些功能。只是没有等效的Web API。
https://github.com/necolas/react-native-web/blob/master/README.md#modules