
Research
/Security News
11 Malicious Go Packages Distribute Obfuscated Remote Payloads
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
react-network-status
Advanced tools
npm i react-network-status
or yarn add react-network-status
Hook that updates component with the network status offline/online state.
This gives user a flexibility to programmatically render UI components.
import { useNetworkStatus } from "react-network-status";
const App = () => {
const [networkStatus, setNetworkStatus] = useState(true);
const config = {
timeout: 5000,
interval: 1000,
};
useNetworkStatus((networkStatusUpdate) => {
setNetworkStatus(networkStatusUpdate);
}, config);
return <div>You are: {networkStatus ? "online" : "offline"}</div>;
};
NetworkDetector
- Component that can be used in State based Components.
It has no UI but just accepts config and onChange event.
import { NetworkDetector } from "react-network-status";
class App extends Component {
state = {
networkStatus: true,
};
config = {
timeout: 5000,
interval: 1000,
};
onNetworkStatusChange = (networkStatus: boolean) => {
this.setState({ networkStatus });
};
render() {
const { networkStatus } = this.state;
return (
<div>
You are: {networkStatus ? "online" : "offline"}
<NetworkDetector
config={this.config}
onChange={this.onNetworkStatusChange}
/>
</div>
);
}
}
<NetworkDetector/>
, and useNetworkStatus
accept the following props:
const config = {
url: // YOUR_POLLING URL,
interval: // YOUR POLLING INTERVAL,
timeout: // YOUR POLLING TIMEOUT
};
onChange: Event that provides status (true or false) as online value of the network.
Prop | Type | Description | Default |
---|---|---|---|
config | Obj or Bool | Config for polling fallback [1] | [see below] |
config.enabled | Boolean | Force polling on or off | Depends on the browser [1] |
config.url | String | URL to pool for connection status | "https://ipv4.icanhazip.com" |
config.interval | Number | How often (in ms) to poll | 5000 |
config.timeout | Number | How long (in ms) before timeout | 5000 |
onChange | Function | Called when connection changes | none |
[1] Polling is only used as a fallback for browsers that don't support the "online"
event. Currently these are Chrome on Windows, Firefox on Windows, and Chrome on Linux.
[2] <NetworkDetector/>
will not render children
.
FAQs
Network status and polling for React Framework
The npm package react-network-status receives a total of 132 weekly downloads. As such, react-network-status popularity was classified as not popular.
We found that react-network-status demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).