1.0.1 • Published 12 months ago

exrun-utils v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

My NPM Library

This library provides utility functions and React hooks for common tasks in JavaScript and React.

Utility Functions

isEmptyObj

Checks if an object is empty (i.e., has no own properties).

Syntax

isEmptyObj(obj: object): boolean

Parameters

  • obj: The object to check.

Return Value

  • Returns true if the object is empty; false otherwise.

isEmptyArray

Checks if an array is empty (i.e., has no elements).

Syntax

isEmptyArray(arr: any[]): boolean

Parameters

  • arr: The array to check.

Return Value

  • Returns true if the array is empty; false otherwise.

useLocalStorage

Description

useLocalStorage is a custom React Hook that simplifies the interaction with localStorage. It enables you to store and retrieve values from localStorage in a more React-like way, using state.

Syntax

const [storedValue, setStoredValue] = useLocalStorage(key, initialValue);

Parameters

  • key (String): The key in localStorage for your value.
  • initialValue (Any): The value you start with if localStorage doesn't have anything stored at the provided key.

Return Value

This hook returns a pair of values: storedValue and setStoredValue.

  • storedValue (Any): The current value of the item in localStorage with the given key.
  • setStoredValue (Function): A function that can be used to update the value of storedValue.

Usage

import useLocalStorage from "./useLocalStorage";

function Component() {
  const [name, setName] = useLocalStorage("name", "Bob");

  // The rest of your component
}

To re-export this utility, you can use the following line of code:

export { default as useLocalStorage } from "./useLocalStorage";
1.0.1

12 months ago

1.0.0

12 months ago