2.0.11 • Published 4 months ago

@ttoss/react-hooks v2.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@ttoss/react-hooks

📚 About

@ttoss/react-hooks is a collection of custom React hooks that can be used to simplify the development of React applications.

Installation

pnpm add @ttoss/react-hooks

API

useDebounce

The useDebounce hook is used to delay the update of a value for a specific amount of time.

import React, { useState } from 'react';
import { useDebounce } from '@ttoss/react-hooks';

export const DebouncedInputComponent = () => {
  const [inputValue, setInputValue] = useState('');
  const debouncedValue = useDebounce(inputValue, 500);

  return (
    <input
      type="text"
      value={inputValue}
      onChange={(e) => setInputValue(e.target.value)}
      placeholder="Type to search..."
    />
  );
};

useLocalStorage

The useLocalStorage hook is used to store and retrieve values from the local storage.

import * as React from 'react';
import { useLocalStorage } from '@ttoss/react-hooks';

export const LocalStorageComponent = () => {
  const [value, setValue] = useLocalStorage('key', 'default value');

  return (
    <div>
      <input
        type="text"
        value={value}
        onChange={(e) => setValue(e.target.value)}
        placeholder="Type to save..."
      />
    </div>
  );
};

It uses the localStorage storage by default, but you can also use the sessionStorage storage by passing the Storage option.

const [value, setValue] = useLocalStorage('key', 'default value', {
  storage: window.sessionStorage,
});

useScript

The useScript hook is used to load external scripts into your React component.

import React from 'react';
import { useScript } from '@ttoss/react-hooks';

export const ComponentWithScript = () => {
  const url = 'https://your-domain.com/bundle-api.js';
  const { status } = useScript(url);

  return <div>{status === 'ready' ? 'Script loaded' : 'Loading'}</div>;
};
2.0.11

4 months ago

2.0.10

5 months ago

2.0.7

6 months ago

2.0.9

6 months ago

2.0.8

6 months ago

2.0.6

7 months ago

2.0.5

7 months ago

2.0.3

9 months ago

2.0.2

9 months ago

2.0.4

9 months ago

2.0.1

9 months ago

2.0.0

10 months ago

1.25.15

10 months ago

1.25.13

10 months ago

1.25.14

10 months ago

1.25.11

1 year ago

1.25.12

12 months ago

1.25.10

1 year ago

1.25.9

1 year ago

1.25.8

1 year ago

1.25.7

1 year ago

1.25.6

1 year ago

1.25.5

1 year ago

1.25.4

1 year ago

1.25.3

1 year ago

1.25.2

1 year ago

1.25.1

1 year ago

1.25.0

1 year ago

1.24.6

2 years ago

1.24.5

2 years ago

1.24.3

2 years ago

1.24.4

2 years ago

1.24.1

2 years ago

1.24.2

2 years ago

1.24.0

2 years ago

1.23.6

2 years ago

1.23.7

2 years ago

1.23.4

2 years ago

1.23.5

2 years ago

1.23.2

2 years ago

1.23.0

2 years ago

1.23.1

2 years ago

1.22.0

2 years ago

1.21.16

2 years ago

1.21.15

2 years ago

1.21.14

2 years ago