1.5.1 • Published 1 year ago

react-hooks-enhanced v1.5.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-hooks-enhanced

Publish to NPM License NPM version downloads vulns

Like this Module? Consider Starring the repo https://img.shields.io/github/stars/dosullivan557/react-hooks-enhanced?style=social

A library of enhanced and highly reusable React hooks for common tasks and functionality.

Installation

To install the latest version of react-hooks-enhanced, run the following command:

npm install react-hooks-enhanced

Hooks

useToggle

import { useToggle } from "react-hooks-enhanced";
function App() {
  const [value, toggleValue] = useToggle(false);
  return (
    <div className="App">
      <p>{JSON.stringify(value)}</p>
      <button onClick={toggleValue}>Toggle {value}</button>
      <div>{value}</div>
    </div>
  );
}

export default App;

useAsyncHook

import { useAsyncHook } from "react-hooks-enhanced";
function App(props) {
  const [result, error, isLoading] = useAsyncHook(props.processData);
  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Something went wrong</div>;
  return (
    <div className="App">
      <p>{JSON.stringify(result)}</p>
      <div>{value}</div>
    </div>
  );
}

export default App;

useDebounce

import React, { useState } from "react";
import { useDebounce } from "react-hooks-enhanced";

const ExampleComponent = () => {
  const [searchTerm, setSearchTerm] = useState("");
  const debouncedSearchTerm = useDebounce(searchTerm, 500);

  useEffect(() => {
    // Make API call or perform search with debouncedSearchTerm
  }, [debouncedSearchTerm]);

  return (
    <div>
      <input
        type="text"
        value={searchTerm}
        onChange={(e) => setSearchTerm(e.target.value)}
      />
    </div>
  );
};

export default ExampleComponent;

useValidatedForm

There are a few regular expressions built in. See below how to use. See here what regular expressions are included.

import React, { useState } from "react";
import { useValidatedForm, regex } from "react-hooks-enhanced";

function App() {
  const [value, setValue, isValid] = useValidatedForm(regex.emailAddress);
  return (
    <div className="App">
      <input onChange={(e) => setValue(e.target.value)} />
      <p>{JSON.stringify(isValid)}</p>
    </div>
  );
}

export default App;

useFetch

import React, { useState } from "react";
import { useFetch } from "react-hooks-enhanced";

function App() {
  const [value, setValue, isValid] = useFetch("www.google.com", { a: 1 }, 'Accept':"*/*");
  return (
    <div className="App">
      <p>{JSON.stringify(value)}</p>
    </div>
  );
}

export default App;

Regular Expressions

  • Postcode
  • Email Address
  • Complex Password
  • Moderate Password
  • AlphaNumeric Value
  • Username
  • Url
  • International Phone Number

Contributing

If you would like to contribute to the react-hooks-enhanced library, please fork the repository and submit a pull request. All contributions are welcome!

License

The react-hooks-enhanced library is open-source software licensed under the MIT license.

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago