netsignal
v1.1.0
Published
Ultra-fast network state for React Native 0.80+ (New Architecture)
Maintainers
Readme
NetSignal
Ultra-fast network state for React Native 0.80+ (New Architecture Only, Android)
0.3ms latency | TurboModule powered | ~300 lines total
Requirements
- React Native 0.80+
- New Architecture enabled
- Android only (iOS/Web not yet supported)
- Kotlin 1.9+
Installation
npm install netsignalEnable New Architecture
In android/gradle.properties:
newArchEnabled=trueAdd Permission
In AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />Usage
import NetSignal, { useNetworkState } from 'netsignal';
// Instant checks (0.3ms)
if (NetSignal.isConnected()) {
console.log('Connected via:', NetSignal.getConnectionType());
}
// React component
function StatusBar() {
const network = useNetworkState();
if (!network.connected) return <Text>Offline</Text>;
return <Text>Network: {network.type}</Text>;
}API
Synchronous Methods (0.3ms)
NetSignal.isConnected() // boolean
NetSignal.getConnectionType() // "wifi" | "cellular" | "ethernet" | "none"
NetSignal.getActiveConnectionCount() // number
NetSignal.hasMultipleConnections() // boolean
NetSignal.getSimpleSummary() // all info in one callAsync Methods
const connections = await NetSignal.getAllActiveConnections();
// [{ type: "wifi", hasInternet: true, isMetered: false }]Events
const unsubscribe = NetSignal.addEventListener((event) => {
console.log('Network changed:', event.isConnected);
});addEventListener runs in parallel with the hook store — if you also use useNetworkState (or a sibling hook), both your callback and the hook will fire on every native event. Pick one per component to avoid redundant work.
React Hooks
const network = useNetworkState(); // full state
const connected = useIsConnected(); // just boolean
const type = useConnectionType(); // just typeAll hooks share a single native subscription via useSyncExternalStore.
Architecture
netsignal/
├── android/
│ ├── build.gradle
│ └── src/main/java/com/netsignal/
│ ├── NetSignalTurboModule.kt
│ └── NetSignalTurboPackage.kt
├── src/
│ ├── NativeNetSignal.ts (Codegen spec)
│ └── index.tsx (JS API + hooks)
├── __tests__/ (Jest test suite)
└── example/ (Demo app)Testing
npm test21 tests covering all API methods, hooks, event subscriptions, and shared subscription behavior.
TypeScript
Full TypeScript support with strict types:
import NetSignal, {
ConnectionType,
NetworkState,
Connection,
} from 'netsignal';
const type: ConnectionType = NetSignal.getConnectionType();
// "wifi" | "cellular" | "ethernet" | "none" | "unknown"Why New Architecture Only?
- 10x faster than old bridge (0.3ms vs 3ms)
- Simpler code — no bridge complexity
- Type safe — Codegen ensures correctness
- Future proof — React Native's direction
License
MIT
