1.1.12 • Published 1 year ago
@piximind/custom-hook v1.1.12
Installation
Using npm
$ npm i -g npm
$ npm i react react-dom @piximind/validation @piximind/custom-hook
Pre requirements:
$ npm i react version 18
$ npm i @piximind/validation
useEffectOnce:
code :
useEffectOnce(() => {
console.log("useEffectOnce");
})
this runs only once at the component build level
useUpdateEffect:
code :
useUpdateEffect(() => {
console.log("useUpdateEffect");
},[DependencyList])
this launches after modifying dependency
useWindowSize:
code :
const { width, height } = useWindowSize()
return screen size
useOnlineStatus:
code :
const onLineStatus = useOnlineStatus()
return network status
useEventListener:
code :
useEventListener("event" ,callbackFunction)
create event listener
useClickOutside:
code :
useClickOutside(React.ref ,callbackFunction)
detect element clict out side
useCustomState:
code :
const[state, setState]=useCustomState(value)
useForm:
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:
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
}