Where is a reasonable place to check for NetInfo.isConnected in a react-native app? | بلاگ

Where is a reasonable place to check for NetInfo.isConnected in a react-native app?

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

Given a very basic requirement like "show a 'you are offline' component" when the phone is not connected, where is a reasonable place to handle this?

I know there are more in depth ways to go about this, I'm just looking to get a "hello world" version of the feature. And also looking to learn a little more about where other's are putting/checking this.

I suppose the below setup will not be updated like if you used [connectionChange][1].

import Expo from 'expo';
import React from 'react';
import { View } from 'react-native';


// VERY TOP LEVEL COMPONENT
class App extends React.Component {
  state = {
    online: true
  }
  handleConnectivityChange = (isConnected) => {
    this.setState({
      online: isConnected
    });
  }
  componentDidMount(){
   NetInfo.isConnected
   .fetch()
   .then(this.handleFirstConnectivityChange);
  }
  render() {

    if (!this.state.online) { return null } // show a 'you are offline' component

    return (
        
              
            
    );
  }
}



export default App;
asked 28 secs ago
A.com

...
نویسنده : استخدام کار بازدید : 10 تاريخ : سه شنبه 24 بهمن 1396 ساعت: 22:13