open-index/open-npm huggingface dataset:
npm package: @rtbjs/network-speed-test
Description: Get the network speed in react.
Author: AndriiPopov
Latest version: 1.0.2

# network-speed-test from React ToolboxJS

Get the network speed in react.

- [network-speed-test from React ToolboxJS](#network-speed-test-from-react-toolboxjs)
  - [Installation- @rtbjs/network-speed-test](#installation--rtbjsnetwork-speed-test)
  - [Usage](#usage)
  - [Issues tracker](#issues-tracker)

## Installation- [@rtbjs/network-speed-test](#@rtbjs/network-speed-test)

To install `@rtbjs/network-speed-test`, simply use npm or yarn:

```bash
npm install @rtbjs/network-speed-test
# or
yarn add @rtbjs/network-speed-test
```

## Usage

1. Import `useNetworkSpeedTest` hook from `@rtbjs/network-speed-test`.
2. Call `runTest` returned from the hook.
3. The result of the test can be obtained from the `download` and `upload` objects returned from the hook.

```jsx
import { useNetworkSpeedTest } from '@rtbjs/network-speed-test';
import { useEffect } from 'react';

const App = () => {
  const { runTest, download, upload } = useNetworkSpeedTest();

  useEffect(() => {
    runTest();
  }, []);

  console.log('Download speed is:', download);
  console.log('Upload speed is:', upload);

  return <div>My component</div>;
};

export default App;
```

Run the upload test before the download test:

```jsx
runTest({
  runUploadBeforeDownload: true,
});
```

Run only the download test:

```jsx
runTest({
  upload: false,
});
```

Run only the upload test:

```jsx
runTest({
  download: false,
});
```

Types:

```jsx
type UseNetworkSpeedTest = {
  runTest: (options?: RunTestOptions) => void; // To run the test
  download: {
    isRunning: boolean; // If the download test is currently running
    isComplete: boolean; // If the test has been completed
    result: {
      error?: any; // Error
      elapsedTime?: number; // How much time the test took
      meanClientMbps?: number; // The speed in Mbps
      numberOfBytes?: number; // How much data has been sent
    };
  };
  upload: {
    isRunning: boolean; // If the upload test is currently running
    isComplete: boolean; // If the test has been completed
    result: {
      error?: any; // Error
      elapsedTime?: number; // How much time the test took
      meanClientMbps?: number; // The speed in Mbps
      numberOfBytes?: number; // How much data has been sent
    };
  };
  isRunning: boolean; // If one of the tests is currently running
  isComplete: boolean; // If the both tests have been completed
};

type RunTestOptions = {
  download?: boolean; // Set to false if the download test is not needed
  upload?: boolean; // Set to false if the upload test is not needed
  runUploadBeforeDownload?: boolean; // Set to true if the upload test should be run first
};
```

## Issues tracker

Please report any issues and feature requests to: [issues tracker](https://github.com/toolbox-js/issues/issues)

---
npm package: @rtbjs/use-conditional-hook
Description: Conditionally call react hooks. Finally!!!
Author: AndriiPopov
Latest version: 1.0.0

# useConditionalHook

Conditionally call react hooks. Finally!!!

- [useConditionalHook](#useconditionalhook)
  - [Installation](#installation)
  - [Usage](#usage)
  - [Types](#types)
  - [Issues tracker](#issues-tracker)

## Installation

To install `@rtbjs/use-conditional-hook`, simply use npm or yarn:

```bash
npm install @rtbjs/use-conditional-hook
# or
yarn add @rtbjs/use-conditional-hook
```

## Usage

1. Example with react `useEffect`:

```jsx
import { useEffect } from 'react';
import { useConditionalHook } from '@rtbjs/use-conditional-hook';

const App = () => {
  const [value, setValue] = useState(0);

  // Returns context that needs to be rendered
  const { context } = useConditionalHook(
    useEffect, // The hook to call
    [
      () => {
        console.log('useEffect');
      },
      [],
    ], // Array of arguents
    value > 0 // Condition for calling the hook
  );

  return (
    <div>
      <button onClick={() => setValue(value - 1)}>Decrement</button>
      <button onClick={() => setValue(value + 1)}>Increment</button>
      {context}
    </div>
  );
};

export { App };
```

2. Example with react `@rtbjs/use-network-speed` that returns a value:

```jsx
import { useNetworkSpeedTest } from '@rtbjs/use-network-speed';
import { useConditionalHook } from '@rtbjs/use-conditional-hook';

const App = () => {
  const [value, setValue] = useState(0);

  // Returns the return from the hook
  const { context, result } = useConditionalHook(
    useNetworkSpeedTest,
    [],
    value > 0
  );

  // Run the test
  useEffect(() => {
    if (res?.runTest) res.runTest();
  }, [!!res?.runTest]);

  console.log(res);

  return (
    <div>
      <button onClick={() => setValue(value - 1)}>Decrement</button>
      <button onClick={() => setValue(value + 1)}>Increment</button>
      {context}
    </div>
  );
};

export { App };
```

## Types

```jsx
type useConditionalHook = {
  hook: any,
  args: Array<any>,
  isRendered: boolean
};
```

## Issues tracker

Please report any issues and feature requests to: [issues tracker](https://github.com/toolbox-js/issues/issues)

---