Skip to content

NetInfo.isConnected, it's "change" event should not trigger on componentWillMount #11041

@jinlong

Description

@jinlong

when component will mount, two "console.log" are output. but i don't change the network

code as follow:

componentWillMount() {
    NetInfo.isConnected.fetch().done(isConnected => {
        console.log('First, is ' + (isConnected ? 'online' : 'offline'));

    });
    
    NetInfo.isConnected.addEventListener('change', (isConnected) => {
        console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
        
    });
    
}

run result:

11-21 18:30:28.285 14419-23251/com.android.browser I/ReactNativeJS: Then, is online
11-21 18:30:28.335 14419-23251/com.android.browser I/ReactNativeJS: First, is online

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions