UNPKG

3.41 kBTypeScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9import * as Types from './internal/types';
10/**
11 * Configures the library with the given configuration. Note that calling this will stop all
12 * previously added listeners from being called again. It is best to call this right when your
13 * application is started to avoid issues. The configuration sets up a global singleton instance.
14 *
15 * @param configuration The new configuration to set.
16 */
17export declare function configure(configuration: Partial<Types.NetInfoConfiguration>): void;
18/**
19 * Returns a `Promise` that resolves to a `NetInfoState` object.
20 * This function operates on the global singleton instance configured using `configure()`
21 *
22 * @param [requestedInterface] interface from which to obtain the information
23 *
24 * @returns A Promise which contains the current connection state.
25 */
26export declare function fetch(requestedInterface?: string): Promise<Types.NetInfoState>;
27/**
28 * Force-refreshes the internal state of the global singleton managed by this library.
29 *
30 * @returns A Promise which contains the updated connection state.
31 */
32export declare function refresh(): Promise<Types.NetInfoState>;
33/**
34 * Subscribe to the global singleton's connection information. The callback is called with a parameter of type
35 * [`NetInfoState`](README.md#netinfostate) whenever the connection state changes. Your listener
36 * will be called with the latest information soon after you subscribe and then with any
37 * subsequent changes afterwards. You should not assume that the listener is called in the same
38 * way across devices or platforms.
39 *
40 * @param listener The listener which is called when the network state changes.
41 *
42 * @returns A function which can be called to unsubscribe.
43 */
44export declare function addEventListener(listener: Types.NetInfoChangeHandler): Types.NetInfoSubscription;
45/**
46 * A React Hook into this library's singleton which updates when the connection state changes.
47 *
48 * @param {Partial<Types.NetInfoConfiguration>} configuration - Configure the isolated network checker managed by this hook
49 *
50 * @returns The connection state.
51 */
52export declare function useNetInfo(configuration?: Partial<Types.NetInfoConfiguration>): Types.NetInfoState;
53/**
54 * A React Hook which manages an isolated instance of the network info manager.
55 * This is not a hook into a singleton shared state. NetInfo.configure, NetInfo.addEventListener,
56 * NetInfo.fetch, NetInfo.refresh are performed on a global singleton and have no affect on this hook.
57 * @param {boolean} isPaused - Pause the internal network checks.
58 * @param {Partial<Types.NetInfoConfiguration>} configuration - Configure the isolated network checker managed by this hook
59 *
60 * @returns the netInfo state and a refresh function
61 */
62export declare function useNetInfoInstance(isPaused?: boolean, configuration?: Partial<Types.NetInfoConfiguration>): {
63 netInfo: Types.NetInfoState;
64 refresh: () => void;
65};
66export * from './internal/types';
67declare const _default: {
68 configure: typeof configure;
69 fetch: typeof fetch;
70 refresh: typeof refresh;
71 addEventListener: typeof addEventListener;
72 useNetInfo: typeof useNetInfo;
73 useNetInfoInstance: typeof useNetInfoInstance;
74};
75export default _default;