Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add imperative api to refresh state (#594)
* feat: add imperative api to refresh state * docs: document refresh in README * Add example to example app * Update netinfo mock with refresh method
- Loading branch information
1 parent
7f040ce
commit 1d7b751
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import {Text, View, TouchableOpacity} from 'react-native'; | ||
import NetInfo from '../src'; | ||
|
||
interface State { | ||
connectionInfo: string; | ||
} | ||
|
||
export default class ConnectionInfoCurrent extends React.Component< | ||
Record<string, unknown>, | ||
State | ||
> { | ||
state = { | ||
connectionInfo: 'Tap to refresh state', | ||
}; | ||
|
||
componentDidMount(): void { | ||
this._refreshState(); | ||
} | ||
|
||
_refreshState = async (): Promise<void> => { | ||
const state = await NetInfo.refresh(); | ||
this.setState({ | ||
connectionInfo: JSON.stringify(state), | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View> | ||
<TouchableOpacity onPress={this._refreshState}> | ||
<Text style={{color: 'black'}}>{this.state.connectionInfo}</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters