UNPKG

2.06 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.
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 *
21 * @param [requestedInterface] interface from which to obtain the information
22 *
23 * @returns A Promise which contains the current connection state.
24 */
25export declare function fetch(requestedInterface?: string): Promise<Types.NetInfoState>;
26/**
27 * Subscribe to connection information. The callback is called with a parameter of type
28 * [`NetInfoState`](README.md#netinfostate) whenever the connection state changes. Your listener
29 * will be called with the latest information soon after you subscribe and then with any
30 * subsequent changes afterwards. You should not assume that the listener is called in the same
31 * way across devices or platforms.
32 *
33 * @param listener The listener which is called when the network state changes.
34 *
35 * @returns A function which can be called to unsubscribe.
36 */
37export declare function addEventListener(listener: Types.NetInfoChangeHandler): Types.NetInfoSubscription;
38/**
39 * A React Hook which updates when the connection state changes.
40 *
41 * @returns The connection state.
42 */
43export declare function useNetInfo(configuration?: Partial<Types.NetInfoConfiguration>): Types.NetInfoState;
44export * from './internal/types';
45declare const _default: {
46 configure: typeof configure;
47 fetch: typeof fetch;
48 addEventListener: typeof addEventListener;
49 useNetInfo: typeof useNetInfo;
50};
51export default _default;