# @piximind/custom-hook

> React Custom Hook

Latest version **1.1.12** (published 2023-03-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install @piximind/custom-hook
pnpm add @piximind/custom-hook
yarn add @piximind/custom-hook
bun add @piximind/custom-hook
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2023-03-23 |
| First published | 2022-12-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 36.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Taieb_Feki |
| Maintainers | technical.user |

## Links

- npm: https://www.npmjs.com/package/@piximind/custom-hook
- npm.io page: https://npm.io/package/@piximind/custom-hook

## Recent versions

- 1.1.12 (latest) — 2023-03-23
- 1.1.11 — 2023-03-23
- 1.1.10 — 2023-02-26
- 1.1.9 — 2023-01-27
- 1.1.8 — 2023-01-23
- 1.1.7 — 2023-01-04
- 1.1.6 — 2023-01-02
- 1.1.5 — 2023-01-02
- 1.1.4 — 2023-01-02
- 1.1.3 — 2023-01-02
- 1.1.2 — 2022-12-29
- 1.1.1 — 2022-12-29
- 1.1.0 — 2022-12-29
- 1.0.0 — 2022-12-26

## README

## Installation
Using npm
  ```shell
$ npm i -g npm
$ npm i react react-dom @piximind/validation @piximind/custom-hook
```
Pre requirements:
```shell
$ npm i react version 18
$ npm i @piximind/validation
```

## useEffectOnce:
```jsx
code :
useEffectOnce(() => {
  console.log("useEffectOnce");
})
this runs only once at the component build level
```


## useUpdateEffect:
```jsx
code :
useUpdateEffect(() => {
  console.log("useUpdateEffect");
},[DependencyList])
this launches after modifying dependency
```


## useWindowSize:
```jsx
code :
const { width, height } = useWindowSize()
return screen size
```


## useOnlineStatus:
```jsx
code :
const onLineStatus = useOnlineStatus()
return network status
```


## useEventListener:
```jsx
code :
useEventListener("event" ,callbackFunction)
create event listener
```


## useClickOutside:
```jsx
code :
useClickOutside(React.ref ,callbackFunction)
detect element clict out side
```
## useCustomState:
```jsx
code :
const[state, setState]=useCustomState(value)
```
## useForm:
```jsx
code :
const{state, onChange, onValidForm, isFormValid ,onReset}=useForm(isRealTimeValidation: true,data:IListElementUseForm)

```
onReset function description : 
if you pass a false param into the onReset function the form will be setten to initial state, else the form will be totally emptied
## Interfaces:
```jsx
enum EListFunction {
    isMail = "isMail",
    hasUperCase = "hasUperCase",
    hasLowerCase = "hasLowerCase",
    hasNumber = "hasNumber",
    isEmpty = "isEmpty",
    isNumber = "isNumber",
    isDate = "isDate",
    isUrl = "isUrl",
    isDateValidation = "isDateValidation",
    hasAlpha = "hasAlpha",
    hasSpecial = "hasSpecial",
    hasSpecialDate = "hasSpecialDate",
    checkIsDate = "checkIsDate",
    isNotEmpty = "isNotEmpty",
    isArray = "isArray",
    isTrue = "isTrue",
}
interface IRule {
    priority: number,
    function: EListFunction,
    messageError: string,
}

interface IListRules extends Array<IRule> { }

interface IElementUseForm {
    value: string | number | boolean,
    isRealTimeValidation?: boolean,
    rules?: IListRules,
    successMessage?: string,
    key: string
}

interface IListElementUseForm extends Array<IElementUseForm> { }

interface IUseForm {
    isRealTimeValidation?: boolean,
    data: IListElementUseForm
}
interface IElementState {
    value: string | number | boolean,
    isValid: boolean,
    successMessage: string,
    isInvalid: boolean,
    errorMessage: string,
}

interface IState {
    [key: string]: IElementState;
}

interface IOnChnage {
    value: string | number | boolean,
    key: string
}

interface IUseFormResult {
    state: IState,
    onChange: Function,
    onValidForm: Function,
    isFormValid: boolean,
    onReset: Function,
    onUpdateData: Function,
    onUpdateState: Function
}

```

---
_Source: https://npm.io/package/@piximind/custom-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
